undefined reference errors after following manual
Dear ObjectboxTeam, i tried setting up ObjectBox for c++ as told in the manual. After changing CmakeLists.txt to find the library i now keep getting undefined reference errors
- ObjectBox version: [0.17.0]
- C++ version: [20](i reproduced the error on different standards as well.)
- OS: [linux mint]
- IDE [CLion]
This is my Cmakelists.txt
cmake_minimum_required(VERSION 3.22)
project(objectboxtest)
set(CMAKE_CXX_STANDARD 20)
include(FetchContent)
FetchContent_Declare(
objectbox
GIT_REPOSITORY https://github.com/objectbox/objectbox-c.git
GIT_TAG v0.17.0
)
FetchContent_MakeAvailable(objectbox)
include_directories(cmake-build-debug/_deps/objectbox-sync-download-src/include)
FetchContent_Declare(
flatbuffers
GIT_REPOSITORY https://github.com/google/flatbuffers.git
GIT_TAG v2.0.0
)
FetchContent_MakeAvailable(flatbuffers)
file(COPY ${CMAKE_BINARY_DIR}/_deps/flatbuffers-src/include/flatbuffers
DESTINATION "_deps/objectbox-sync-download-src/include/")
add_executable(objectboxtest main.cpp main.h objectbox-model.h tasklist.obx.cpp tasklist.obx.hpp)
target_link_libraries(objectbox INTERFACE objectbox)
And this is the error i keep getting
====================[ Build | objectboxtest | Debug ]===========================
/opt/clion-2022.1.3/bin/cmake/linux/bin/cmake --build /home/jonas/CLionProjects/objectboxtest/cmake-build-debug --target objectboxtest -j 1
[1/1] Linking CXX executable objectboxtest
FAILED: objectboxtest
: && /usr/bin/g++ -g CMakeFiles/objectboxtest.dir/main.cpp.o CMakeFiles/objectboxtest.dir/tasklist.obx.cpp.o -o objectboxtest && :
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::(anonymous namespace)::throwLastError(int)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:78: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:81: undefined reference to `obx_last_error_message'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:86: undefined reference to `obx_last_error_message'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::(anonymous namespace)::checkErrOrThrow(int)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:94: undefined reference to `obx_last_error_code'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::(anonymous namespace)::CursorTx::~CursorTx()':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:532: undefined reference to `obx_cursor_close'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::(anonymous namespace)::idVectorOrThrow(OBX_id_array*)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:569: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:578: undefined reference to `obx_id_array_free'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:581: undefined reference to `obx_id_array_free'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::(anonymous namespace)::QCGroup::applyTo(OBX_query_builder*, bool) const':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:697: undefined reference to `obx_qb_any'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:698: undefined reference to `obx_qb_all'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `create_obx_model':
/home/jonas/CLionProjects/objectboxtest/objectbox-model.h:23: undefined reference to `obx_model'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/objectbox-model.h:26: undefined reference to `obx_model_entity'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/objectbox-model.h:27: undefined reference to `obx_model_property'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/objectbox-model.h:28: undefined reference to `obx_model_property_flags'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/objectbox-model.h:29: undefined reference to `obx_model_property'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/objectbox-model.h:30: undefined reference to `obx_model_property'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/objectbox-model.h:31: undefined reference to `obx_model_property_flags'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/objectbox-model.h:32: undefined reference to `obx_model_property'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/objectbox-model.h:33: undefined reference to `obx_model_property_flags'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/objectbox-model.h:34: undefined reference to `obx_model_entity_last_property_id'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/objectbox-model.h:36: undefined reference to `obx_model_last_entity_id'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `OBX_store_options* obx::(anonymous namespace)::checkPtrOrThrow<OBX_store_options>(OBX_store_options*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_message'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `OBX_store* obx::(anonymous namespace)::checkPtrOrThrow<OBX_store>(OBX_store*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_message'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `OBX_txn* obx::(anonymous namespace)::checkPtrOrThrow<OBX_txn>(OBX_txn*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_message'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `OBX_cursor* obx::(anonymous namespace)::checkPtrOrThrow<OBX_cursor>(OBX_cursor*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_message'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `OBX_box* obx::(anonymous namespace)::checkPtrOrThrow<OBX_box>(OBX_box*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_message'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Options::Options()':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:152: undefined reference to `obx_opt'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Options::~Options()':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:159: undefined reference to `obx_opt_free'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Options::model(OBX_model*)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:164: undefined reference to `obx_opt_model'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Store::Store(obx::Options&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:404: undefined reference to `obx_store_open'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Transaction::Transaction(obx::Store&, obx::TxMode)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:462: undefined reference to `obx_txn_write'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:462: undefined reference to `obx_txn_read'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Transaction::closeNoThrow()':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:500: undefined reference to `obx_txn_close'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::(anonymous namespace)::CursorTx::CursorTx(obx::TxMode, obx::Store&, unsigned int)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:521: undefined reference to `obx_cursor'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Store::~Store()':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:2192: undefined reference to `obx_store_close'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Box<Task>::Box(obx::Store&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:1652: undefined reference to `obx_box'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Box<Task>::put(Task const&, OBXPutMode)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:1795: undefined reference to `obx_box_put_object4'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:1797: undefined reference to `obx_last_error_code'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Box<Task>::remove(unsigned long)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:1844: undefined reference to `obx_box_remove'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/main.cpp.o: in function `obx::Box<Task>::get(unsigned long, Task&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:1721: undefined reference to `obx_cursor_get'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/tasklist.obx.cpp.o: in function `obx::(anonymous namespace)::throwLastError(int)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:78: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:81: undefined reference to `obx_last_error_message'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:86: undefined reference to `obx_last_error_message'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/tasklist.obx.cpp.o: in function `obx::(anonymous namespace)::checkErrOrThrow(int)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:94: undefined reference to `obx_last_error_code'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/tasklist.obx.cpp.o: in function `obx::(anonymous namespace)::idVectorOrThrow(OBX_id_array*)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:569: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:578: undefined reference to `obx_id_array_free'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:581: undefined reference to `obx_id_array_free'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/tasklist.obx.cpp.o: in function `obx::(anonymous namespace)::QCGroup::applyTo(OBX_query_builder*, bool) const':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:697: undefined reference to `obx_qb_any'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:698: undefined reference to `obx_qb_all'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/tasklist.obx.cpp.o: in function `OBX_store_options* obx::(anonymous namespace)::checkPtrOrThrow<OBX_store_options>(OBX_store_options*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_message'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/tasklist.obx.cpp.o: in function `OBX_store* obx::(anonymous namespace)::checkPtrOrThrow<OBX_store>(OBX_store*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_message'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/tasklist.obx.cpp.o: in function `OBX_txn* obx::(anonymous namespace)::checkPtrOrThrow<OBX_txn>(OBX_txn*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_message'
/usr/bin/ld: CMakeFiles/objectboxtest.dir/tasklist.obx.cpp.o: in function `OBX_cursor* obx::(anonymous namespace)::checkPtrOrThrow<OBX_cursor>(OBX_cursor*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_code'
/usr/bin/ld: /home/jonas/CLionProjects/objectboxtest/cmake-build-debug/_deps/objectbox-sync-download-src/include/objectbox.hpp:105: undefined reference to `obx_last_error_message'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Thank you very much in advance. Jonas
Can you please send me the link to the manual that you were using?
Please note that our most up to date docs are located here: https://cpp.objectbox.io/installation. Could you try once again, but following the steps from there?
I reply here because I have unresolved references as well with 0.17, though I think the Op might have a different problem. For me, the missing symbols seem all to be from the internal namespace. I'm sure my configuration is correct because it compiles and links, fine when I replace include and lib from 0.17 with those from 0.16. Environment is VS 2019, both x64 and x68 are affected. I think you might be missing the inline declaration for some functions in the internal namespace.
Sorry that it took me so long to answer here as i was on vacation. I followed the manual you sent me and checking the ObjectBox version went fine. But when i followed the first example, and try to run it, i get the following errors:
/opt/clion-2022.2.1/bin/cmake/linux/bin/cmake --build /home/jonas/CLionProjects/objtest/cmake-build-debug --target objtest -j 1
[1/1] Linking CXX executable objtest
FAILED: objtest
: && /usr/bin/c++ -g CMakeFiles/objtest.dir/main.cpp.o -o objtest -Wl,-rpath,/home/jonas/CLionProjects/objtest/cmake-build-debug/_deps/objectbox-download-src/lib _deps/objectbox-download-src/lib/libobjectbox.so && :
/usr/bin/ld: CMakeFiles/objtest.dir/main.cpp.o: in function `obx::Box<Task>::put(Task const&, OBXPutMode)':
/home/jonas/CLionProjects/objtest/cmake-build-debug/_deps/objectbox-download-src/include/objectbox.hpp:1794: undefined reference to `Task::_OBX_MetaInfo::toFlatBuffer(flatbuffers::FlatBufferBuilder&, Task const&)'
/usr/bin/ld: CMakeFiles/objtest.dir/main.cpp.o: in function `obx::Box<Task>::get(unsigned long, Task&)':
/home/jonas/CLionProjects/objtest/cmake-build-debug/_deps/objectbox-download-src/include/objectbox.hpp:1724: undefined reference to `Task::_OBX_MetaInfo::fromFlatBuffer(void const*, unsigned long, Task&)'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.