Ask Your Question
0

How I can Add .c libraries in my ROS project?

asked 2019-01-06 05:09:09 -0500

GLinBoy gravatar image

updated 2019-01-09 06:27:33 -0500

I know this question may be duplicated but my problem not solved yet!

Lemme describe, I have fontx.c, fontx.h, pcd8544.c nad pcd8544.h. I added them as library to CMakeLists.txt like:

add_library(fontx
  src/fontx.c
)
add_dependencies(fontx ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(fontx
  ${catkin_LIBRARIES}
)

add_library(pcd8544
  src/pcd8544.c
)
add_dependencies(pcd8544 ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(pcd8544
  ${catkin_LIBRARIES}
)

add_executable(DisplayNode_pub
  src/DisplayNode_pub.cpp
)
add_dependencies(DisplayNode_pub ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(DisplayNode_pub
  ${catkin_LIBRARIES}
)

add_executable(DisplayNode_sub
  src/DisplayNode_sub.cpp
)
add_dependencies(DisplayNode_sub ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(DisplayNode_sub
  fontx pcd8544
  wiringPi pthread
  ${catkin_LIBRARIES}
)

But when I run catkin_make I got undefined reference again! this is my catkin_make output

Base path: /home/hojjat/projects/shared_printer
Source space: /home/hojjat/projects/shared_printer/src
Build space: /home/hojjat/projects/shared_printer/build
Devel space: /home/hojjat/projects/shared_printer/devel
Install space: /home/hojjat/projects/shared_printer/install
####
#### Running command: "cmake /home/hojjat/projects/shared_printer/src -DCMAKE_CXX_FLAGS=-Wall -DCMAKE_C_FLAGS=-Wallcatkin_make -DCMAKE_CXX_FLAGS=-Wall -DCMAKE_C_FLAGS=-Wall -DCATKIN_DEVEL_PREFIX=/home/hojjat/projects/shared_printer/devel -DCMAKE_INSTALL_PREFIX=/home/hojjat/projects/shared_printer/install -G Unix Makefiles" in "/home/hojjat/projects/shared_printer/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/hojjat/projects/shared_printer/devel
-- Using CMAKE_PREFIX_PATH: /home/hojjat/projects/shared_printer/devel;/opt/ros/melodic
-- This workspace overlays: /home/hojjat/projects/shared_printer/devel;/opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.15", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/hojjat/projects/shared_printer/build/test_results
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.15") 
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.14
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - display
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'display'
-- ==> add_subdirectory(display)
-- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy
-- display: 0 messages, 1 services
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hojjat/projects/shared_printer/build
####
#### Running command: "make -j2 -l2" in "/home/hojjat/projects/shared_printer/build"
####
[  0%] Built target std_msgs_generate_messages_nodejs
[  0%] Built target std_msgs_generate_messages_lisp
[  0%] Built target _display_generate_messages_check_deps_DisplayService
[  0%] Built target std_msgs_generate_messages_cpp
[  0%] Built target std_msgs_generate_messages_py
[  0%] Built target std_msgs_generate_messages_eus
[  0%] Built target roscpp_generate_messages_cpp
[  0%] Built target rosgraph_msgs_generate_messages_py
[  0%] Built target rosgraph_msgs_generate_messages_nodejs
[  0%] Built target rosgraph_msgs_generate_messages_lisp
[  0%] Built target rosgraph_msgs_generate_messages_eus
[  0%] Built target roscpp_generate_messages_lisp
[  0%] Built target roscpp_generate_messages_py
[  0%] Built target roscpp_generate_messages_nodejs
[  0%] Built target roscpp_generate_messages_eus
[  0%] Built target _catkin_empty_exported_target
[  0%] Built target rosgraph_msgs_generate_messages_cpp
[  6%] Built target display_generate_messages_nodejs
[ 13%] Built target display_generate_messages_lisp
[ 26%] Built target display_generate_messages_py
[ 33%] Built target display_generate_messages_cpp
[ 46%] Built target display_generate_messages_eus
[ 46%] Built target display_generate_messages
[ 60%] Built target fontx
[ 73%] Built target pcd8544
[ 86%] Built target DisplayNode_pub
[ 93%] Linking CXX executable /home/hojjat/projects/shared_printer/devel/lib/display/DisplayNode_sub
CMakeFiles/DisplayNode_sub.dir/src/DisplayNode_sub.cpp.o: In function `looper(char const*, int)':
DisplayNode_sub.cpp:(.text+0x16f): undefined reference to `Fontx_init(FontxFile*, char const*, char const*)'
DisplayNode_sub.cpp:(.text+0x1c6): undefined reference to `LCDdrawSJISChar(FontxFile*, unsigned char ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-01-06 06:24:49 -0500

gvdhoorn gravatar image

updated 2019-01-06 06:25:50 -0500

I know this question may be duplicated but my problem not solved yet!

It's good that you realise this. Can you please update your post with the Q&As you've found, tried but didn't work?

Edit: I'm pretty sure this is a direct duplicate of #q227146. That's why I ask.

edit flag offensive delete link more

Comments

ohhh thank you man! I lost that answer in my search and and after add this lines

#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif

everything compied fine!!! I try these #q65424 or #q247146 but that you mentioned, I didn't try and that fix my proble

GLinBoy gravatar imageGLinBoy ( 2019-01-06 07:28:58 -0500 )edit

@GLinBoy please use the checkbox at the left to mark a question as solved instead of editing the title. In this case I've done it for you.

tfoote gravatar imagetfoote ( 2019-01-08 18:31:55 -0500 )edit

I'm sorry @tfoot but I can't see any checkbox on left to mark it as solved.

GLinBoy gravatar imageGLinBoy ( 2019-01-09 06:27:53 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-01-06 05:09:09 -0500

Seen: 72 times

Last updated: Jan 09