ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Linking problem Melodic, compiling multiple .cpp files into single

asked 2019-09-07 19:14:50 -0500

Hardyn gravatar image

I am having trouble constructing a node that has several C/CPP files that should be linked into a single. I have googled around for about 1/2 day and I think I have the CMakeLists.txt file correct (obviously I don't).

The files in question build and link correctly outside of ROS (cpp -o SolTrack Soltrack.c Soltrack_RiseSet.c testfn.c -lm), which mean there is something I am missing about the linking options in the CMake file.

The error I am seeing, is below. Excerpts from the CMake file are further below (I cannot attach a file yet).


solar_track.cpp:(.text+0x2d8): undefined reference to SolTrack_RiseSet(Time, Location, Position, RiseSet, double, int, int)
solar_track.cpp:(.text+0x342): undefined reference to `SolTrack(Time, Location, Position*, int, int, int, int)'


find_package(
catkin REQUIRED COMPONENTS
roscpp
std_msgs
${PROJECT_NAME}
)

catkin_package(
INCLUDE_DIRS include
'# LIBRARIES solar_track
CATKIN_DEPENDS roscpp std_msgs
'# DEPENDS system_lib
)

include_directories(
include
${catkin_INCLUDE_DIRS}
)

add_executable(
${PROJECT_NAME}_node
src/SolTrack.c
src/SolTrack_RiseSet.c
src/solar_track.cpp
)

target_link_libraries(
${PROJECT_NAME}_node
${catkin_LIBRARIES}
m #math library
)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-09-08 01:18:24 -0500

Hardyn gravatar image

So the problem was that I was using a classic C "library", which was upsetting the C++ compiler.

After changing my searches a bit, I discovered this fact and the remedy is actually quite straight forward...

extern "C" 
{
  #include "myheader.h"
}

Apparently C and C++ is treated differently and the compiler needs to be told this explicitly.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-09-07 19:14:50 -0500

Seen: 647 times

Last updated: Sep 08 '19