{"id":233,"date":"2022-08-30T14:57:56","date_gmt":"2022-08-30T14:57:56","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/08\/31\/cord-library-that-comes-with-boehm-gc-causes-undefined-reference-errors-record-and-share-programming-errors\/"},"modified":"2022-08-30T14:57:56","modified_gmt":"2022-08-30T14:57:56","slug":"cord-library-that-comes-with-boehm-gc-causes-undefined-reference-errors-record-and-share-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/cord-library-that-comes-with-boehm-gc-causes-undefined-reference-errors-record-and-share-programming-errors\/","title":{"rendered":"&ldquo;cord&rdquo; library that comes with Boehm GC causes undefined reference errors-Record and share programming errors"},"content":{"rendered":"<p>I have a project that uses Boehm GC, so I thought that I might use the <code>cord<\/code> string library that comes with it. The problem is that all my calls to the <code>cord<\/code> functions cause &#8220;undefined reference&#8221; errors.<\/p>\n<p>I do have a file named <code>libcord.so<\/code> in <code>\/usr\/lib<\/code> (this is a Linux system), and I told CMake to link the target with <code>gc<\/code> and <code>cord<\/code>.<\/p>\n<p><strong>Edit in response to comment #1:<\/strong><\/p>\n<p>from <code>CMakeLists.txt<\/code><\/p>\n<pre><code>target_link_libraries(lang gc)\ntarget_link_libraries(lang cord)\n<\/code><\/pre>\n<p>from error message:<\/p>\n<pre><code>..\/lib\/liblang.so: undefined reference to `CORD_substr(char const*, unsigned long, unsigned long)'\n..\/lib\/liblang.so: undefined reference to `CORD_len(char const*)'\n..\/lib\/liblang.so: undefined reference to `CORD_cat(char const*, char const*)'\n..\/lib\/liblang.so: undefined reference to `CORD_cmp(char const*, char const*)'\n..\/lib\/liblang.so: undefined reference to `CORD_to_char_star(char const*)'\n<\/code><\/pre>\n<p><strong>Edit in response to comment #2:<\/strong><\/p>\n<pre><code>$ make -j4 VERBOSE=1\n\/usr\/bin\/cmake -H\/home\/michael\/Projects\/lang -B\/home\/michael\/Projects\/lang\/build --check-build-system CMakeFiles\/Makefile.cmake 0\n\/usr\/bin\/cmake -E cmake_progress_start \/home\/michael\/Projects\/lang\/build\/CMakeFiles \/home\/michael\/Projects\/lang\/build\/CMakeFiles\/progress.marks\n\/usr\/bin\/make -f CMakeFiles\/Makefile2 all\nmake[1]: Entering directory `\/home\/michael\/Projects\/lang\/build'\n\/usr\/bin\/make -f lib\/CMakeFiles\/lang.dir\/build.make lib\/CMakeFiles\/lang.dir\/depend\nmake[2]: Entering directory `\/home\/michael\/Projects\/lang\/build'\ncd \/home\/michael\/Projects\/lang\/build &amp;&amp; \/usr\/bin\/cmake -E cmake_depends \"Unix Makefiles\" \/home\/michael\/Projects\/lang \/home\/michael\/Projects\/lang\/lib \/home\/michael\/Projects\/lang\/build \/home\/michael\/Projects\/lang\/build\/lib \/home\/michael\/Projects\/lang\/build\/lib\/CMakeFiles\/lang.dir\/DependInfo.cmake --color=\nmake[2]: Leaving directory `\/home\/michael\/Projects\/lang\/build'\n\/usr\/bin\/make -f lib\/CMakeFiles\/lang.dir\/build.make lib\/CMakeFiles\/lang.dir\/build\nmake[2]: Entering directory `\/home\/michael\/Projects\/lang\/build'\nmake[2]: Nothing to be done for `lib\/CMakeFiles\/lang.dir\/build'.\nmake[2]: Leaving directory `\/home\/michael\/Projects\/lang\/build'\n\/usr\/bin\/cmake -E cmake_progress_report \/home\/michael\/Projects\/lang\/build\/CMakeFiles  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17\n[ 94%] Built target lang\n\/usr\/bin\/make -f src\/CMakeFiles\/main.dir\/build.make src\/CMakeFiles\/main.dir\/depend\nmake[2]: Entering directory `\/home\/michael\/Projects\/lang\/build'\ncd \/home\/michael\/Projects\/lang\/build &amp;&amp; \/usr\/bin\/cmake -E cmake_depends \"Unix Makefiles\" \/home\/michael\/Projects\/lang \/home\/michael\/Projects\/lang\/src \/home\/michael\/Projects\/lang\/build \/home\/michael\/Projects\/lang\/build\/src \/home\/michael\/Projects\/lang\/build\/src\/CMakeFiles\/main.dir\/DependInfo.cmake --color=\nmake[2]: Leaving directory `\/home\/michael\/Projects\/lang\/build'\n\/usr\/bin\/make -f src\/CMakeFiles\/main.dir\/build.make src\/CMakeFiles\/main.dir\/build\nmake[2]: Entering directory `\/home\/michael\/Projects\/lang\/build'\nLinking CXX executable lang\ncd \/home\/michael\/Projects\/lang\/build\/src &amp;&amp; \/usr\/bin\/cmake -E cmake_link_script CMakeFiles\/main.dir\/link.txt --verbose=1\n\/usr\/bin\/c++      CMakeFiles\/main.dir\/main.cpp.o  -o lang -rdynamic ..\/lib\/liblang.so -lgc -lcord -lgmp -Wl,-rpath,\/home\/michael\/Projects\/lang\/build\/lib \n..\/lib\/liblang.so: undefined reference to `CORD_substr(char const*, unsigned long, unsigned long)'\n..\/lib\/liblang.so: undefined reference to `CORD_len(char const*)'\n..\/lib\/liblang.so: undefined reference to `CORD_cat(char const*, char const*)'\n..\/lib\/liblang.so: undefined reference to `CORD_cmp(char const*, char const*)'\nmake[2]: Leaving directory `\/home\/michael\/Projects\/lang\/build'\nmake[1]: Leaving directory `\/home\/michael\/Projects\/lang\/build'\n..\/lib\/liblang.so: undefined reference to `CORD_to_char_star(char const*)'\ncollect2: ld returned 1 exit status\nmake[2]: *** [src\/lang] Error 1\nmake[1]: *** [src\/CMakeFiles\/main.dir\/all] Error 2\nmake: *** [all] Error 2\n<\/code><\/pre>\n<ol>\n<li>\n<p>From what I can see, the <code>cord.h<\/code> file does not seem to include <code>extern \"C\"<\/code> statements in it, and so the name mangling is being done incorrectly when you are compiling <code>liblang.so<\/code> with a C++ compiler.<\/p>\n<p>In the source where you <code>#include<\/code> you probably need something like:<\/p>\n<pre><code>extern \"C\" {\n#include \"cord.h\"\n}\n<\/code><\/pre>\n<\/li>\n<li>\n<p>This mau help you to solve your problem in CMake:<\/p>\n<p>set_target_properties( PROPERTIES LINKER_LANGUAGE C)<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-08-31 05:31:58. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have a project that uses Boehm GC, so I thought that I might use the cord string library that comes with it. The problem is that all my calls to the cord functions cause &#8220;undefined reference&#8221; errors. I do have a file named libcord.so in \/usr\/lib (this is a Linux system), and I told [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-233","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=233"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/233\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}