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

Multiple definition of main error in catkin_make

asked 2016-01-31 09:16:39 -0500

user23fj239 gravatar image

What am I doing wrong. I checked this but the add_executables seem to be ok. This is my cmakeList.txt
If i only use the server and client example it error is the same. Did I mix something up?

    [ 94%] Built target listener
    Scanning dependencies of target add_two_ints_server
    [100%] Building CXX object test_my_env/CMakeFiles/add_two_ints_server.dir/src/add_two_ints_server.cpp.o
    Linking CXX shared library /home/baum/catkin_ws/devel/lib/libmy_test_lib.so
    CMakeFiles/my_test_lib.dir/src/listener.cpp.o: In function `main':
    listener.cpp:(.text+0x15c): multiple definition of `main'
    CMakeFiles/my_test_lib.dir/src/talker.cpp.o:talker.cpp:(.text+0x0): first defined here
    CMakeFiles/my_test_lib.dir/src/add_two_ints_server.cpp.o: In function `main':
    add_two_ints_server.cpp:(.text+0x2b5): multiple definition of `main'
    CMakeFiles/my_test_lib.dir/src/talker.cpp.o:talker.cpp:(.text+0x0): first defined here
    CMakeFiles/my_test_lib.dir/src/add_two_ints_client.cpp.o: In function `main':
    add_two_ints_client.cpp:(.text+0x0): multiple definition of `main'
    CMakeFiles/my_test_lib.dir/src/talker.cpp.o:talker.cpp:(.text+0x0): first defined here
    collect2: error: ld returned 1 exit status
    make[2]: *** [/home/baum/catkin_ws/devel/lib/libmy_test_lib.so] Error 1
    make[1]: *** [test_my_env/CMakeFiles/my_test_lib.dir/all] Error 2
    make[1]: *** Waiting for unfinished jobs....
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-01-31 09:49:06 -0500

user23fj239 gravatar image

It is very recommendable to have a second workspace to just build this package and I nailed it.
My exported library was the problem. So I commented it but the WHY is still unsolved?

CMake Error at test_my_env/CMakeLists.txt:61 (target_link_libraries):
  Attempt to add link library "/opt/ros/jade/lib/libroscpp.so" to target
  "add_two_ints_server" which is not built in this directory.


## build your library, listing all required C++ source files(no headers)
#set(MY_TEST_LIB_SRC
#   src/talker.cpp 
#   src/listener.cpp 
#   src/add_two_ints_server.cpp 
#   src/add_two_ints_client.cpp)

## my library export
#add_library(my_test_lib ${MY_TEST_LIB_SRC})

## my library depends on
#target_link_libraries(my_test_lib
#                       ${catkin_LIBRARIES} #catkin libraries
#                       ${Boost_LIBRARIES}) #additional non catkin libraries
#add_dependencies(my_test_lib ${catkin_EXPORTED_TARGETS})

## Libraries are installed in a lib/ directory shared by all packages in entire ROS distro
#install(TARGETS my_test_lib
#        ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#        LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#        RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION})
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-01-31 09:16:39 -0500

Seen: 1,444 times

Last updated: Jan 31 '16