I’m setup to program in C++ with WindRiver workbench and I’m able to get all the example programs to compile just fine. I just got started on a new project today, though, trying to modify the WPIlib source files RobotDrive.cpp and RobotDrive.h in my project. I have copied them from the WPIlib project (downloadable from the WPI website) into my project, which is a SimpleRobot.
From reading the C Programming Guide, I assume that one is able to do just this, make modifications to the added WPIlib files, and then everything will magically compile (see page 76 in the guide). Clearly, though, this is not the case (at least in my case :yikes: ).
As far as I can tell, there are no syntactical errors that would keep my code from compiling, and yet I am still getting errors when I go to build the project. There are four functions that each generate two errors in what appears to be the link step (I may be wrong on that one) and the errors, in essence, say that I have multiple definitions of these four functions. Coincidentally, these are the four functions that I didn’t comment out from the original WPIlib files. Their definitions in the .h file did not change, either, to accommodate my modifications.
So here’s what I think is happening: I think that my project is somehow trying to link in the pre-compiled RobotDrive files and throwing me errors where ever it finds conflicts between the ones in my project and the ones in WPIlib.
Finally my question: Has anyone tried to modify parts of WPIlib in a new project to any success? What was your secret? I am kinda stumped right now…
Maybe I just need to sleep on it, but if you guys could think of any solution, I would be hugely appreciative.
Another development to suggest that the real problem is what I think it is: the line numbers for the errors point to locations in my RobotDrive.cpp file that are completely unrelated to the functions in question. I did a quick check to see if those line numbers corresponded to the WPIlib .cpp files and, lo and behold, they did.
I’m almost certain your problem has to do with the fact that the linker is using the wrong libraries. Right click your Project in the Project Explorer, click Properties. Head over to Libraries under Build Properties, and edit the existing entry of “$(WIND_BASE)/target/lib/WPILib.a” to point to your compiled library.
(This is from page 75 of the C Programming Guide)
I just want to clarify what that will do before I go ahead and do it. I understand that there is a precompiled WPIlib somewhere in the WindRiver directory. I also understand that I can compile the WPIlib from the source files available online on the WPI website to make the same WPIlib.a file that is found in the WindRiver directory after installing WorkBench.
What I want to do is modify just RobotDrive.cpp and RobotDrive.h for my project alone. Is what you’re saying that I have to modify the downloadable WPIlib source files, compile that to WPIlib.a, and then include that in my project?
Maybe it’s just me, but I thought that page 76 of the C Programming Guide said all I had to do was add the files I wanted to modify to my project directory and compile.
I have no problem with modifying the WPIlib source files in my WPIlib project and then compiling that to a new WPIlib.a, it’s just that I think there’s another way of doing this.
So, you just pointed out one solution (Thanks!). Does anybody have another? I’ll go take another look at page 76, just to make sure I’m not crazy :yikes: …
The problem is that RobotDrive.cpp and RobotDrive.h depend on other source files. Compiling to a new WPILib.a is probably the easiest way to go around this. (Though there are other ways.)
What modifications do you want to make to those files? Are you sure you aren’t better off putting your custom code in a different file?
It may be easier to create a child class and overwrite the functions you want to replace.
The modifications I am making are to support an as-yet unsupported drive type. I would love to explain more about the drive system, but our mechanical team wouldn’t be too happy with me :rolleyes: .
I’m not really sure what you mean by creating a child class (I’m not exactly a pro with OOP yet, although I have several books I’m learning lots from), but I am interested. It sounds like you are suggesting that I somehow over-rule the function definitions in RobotDrive.cpp and RobotDrive.h. How would you suggest I implement that, if that’s what you’re talking about?
Hey guys. More progress on this topic is being made over on the USFIRST C++ programming forum. Anyone interested in extending/modifying WPILib will probably find it interesting.
Rather than double posting what is on the other forum, this post serves as a bump.