JaciBrunning / Pathfinder

Cross-Platform, Multi-Use Motion Profiling and Trajectory Generation
MIT License
255 stars 78 forks source link

C++ Seemingly not linking in Eclipse Neon with WPILib for 2017 #6

Closed icecube45 closed 7 years ago

icecube45 commented 7 years ago

Hi! This library looks exactly like what I've been looking for, my only issue is that it doesn't appear to link in eclipse neon.

My project outputs the errors of

..\src/Robot.cpp:58: undefined reference to `d2r(double)'
..\src/Robot.cpp:66: undefined reference to `pf_fit_hermite_cubic(Waypoint, Waypoint, Spline*)'
..\src/Robot.cpp:66: undefined reference to `pf_fit_hermite_cubic(Waypoint, Waypoint, Spline*)'
..\src/Robot.cpp:66: undefined reference to `pathfinder_prepare(Waypoint*, int, void (*)(Waypoint,Waypoint,Spline*), int, double, double, double, double, TrajectoryCandidate*)'
..\src/Robot.cpp:71: undefined reference to `pathfinder_generate(TrajectoryCandidate*, Segment*)'
..\src/Robot.cpp:77: undefined reference to `pathfinder_modify_tank(Segment*, int, Segment*, Segment*, double)'

I'm pretty sure I'm linking it correctly, the lib folder is in my search paths for libraries, and the pathfinder library is on the top of my list.

Any help would be greatly appreciated.

JaciBrunning commented 7 years ago

Are you using the 2017 Plugins?

icecube45 commented 7 years ago

Indeed I am

JaciBrunning commented 7 years ago

Try putting the pathfinder libraries in ~/wpilib/user/java, the same place the SRX libraries are stored (if you installed them).

icecube45 commented 7 years ago

I'm using cpp, but putting the includes and library under the cpp section of the wpilib folder (where the third party libraries are) results in no change.

JaciBrunning commented 7 years ago

I've found the issue. It turns out WPILib doesn't link .a files, only .so files. Hold tight and I'll build a .so version for you to include

JaciBrunning commented 7 years ago

Head to the releases and download the C++ fix, export this into your ~/wpilib/user/cpp folder and it should work.

icecube45 commented 7 years ago

Great! I'll try it out tomorrow and report back

Sloth7 commented 7 years ago

Did you get this working? We are having problems linking the .so following the instructions in the wiki.

Kython89 commented 7 years ago

Working with @Sloth7 on this. The .so file in the most recent release is only 27KB. Is this correct? It seems small.

JaciBrunning commented 7 years ago

@Kython89 Yes, this is correct. Pathfinder doesn't have any dependencies so the binary is fairly small. 27KB seems nominal

@Sloth7 don't use the Wiki instructions for this. Put the .so library under ~/wpilib/user/cpp/lib and the header files under ~/wpilib/user/cpp/include

j0n5m1th commented 7 years ago

My team has been working on getting this integrated to a 2017 C++ Command Base project and have been running into the same issue.

I believe the issue is due to name mangling between C and C++. The errors were resolved by adding extern "C" around all of the includes in pathfinder.h. (gist) A clean of the project after adding extern allows the project to build successfully.

I have pulled in both the most recent release with the .so and the previous release with the .a binaries at different times. Both seem to work just fine as far as compiling goes. CTRE, SF2, etc. all seem to have .a binaries and can be pulled in just fine.

Thoughts?

JaciBrunning commented 7 years ago

@CaptainGeneric Pathfinder is designed to be a C library, that can be imported into C++ projects. Does it build successfully if, in your robot program, you use

extern "C" #include "pathfinder.h"

instead of

#include "pathfinder.h"
j0n5m1th commented 7 years ago

Yeah, I wasn't a fan of modifying the header file to get the project to compile. That's definitely not the resolution.

I did try your suggestion (and a few other things) and didn't have any luck by changing the way the robot project includes the library. I'll try to pick this back up tomorrow to see if I can figure out anything else.

Let me know if you have any other ideas. I would be happy to give them a shot.

JaciBrunning commented 7 years ago

Hmm, if adding extern "C" seems to fix it in the pathfinder.h file, I'll put in an ifdef __cplusplus for it. Hold tight, I'll work on something soon

JaciBrunning commented 7 years ago

There's now a fix up that allows Pathfinder to be included with WPILib C++ projects. Get the release here and extract it to ~/wpilib/user/cpp. This should close this issue, if there's anything else related to this issue please reopen it or create a new one

Kython89 commented 7 years ago

@JacisNonsense The latest release you provided works great and we can now link.