Reputation: 11
I'm trying to link libsqlite3.dylib with C++ using CMake, but I keep getting the following error:
Undefined symbols for architecture x86_64:
"_sqlite3_close", referenced from:
OpnavCamera::~OpnavCamera() in opnav_camera.cpp.o
OpnavCamera::updateState() in opnav_camera.cpp.o
"_sqlite3_exec", referenced from:
select_stmt(char const*) in opnav_camera.cpp.o
"_sqlite3_open", referenced from:
OpnavCamera::updateState() in opnav_camera.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [../modules/opnav_camera/_opnav_camera.so] Error 1
make[1]: *** [SimCode/CMakeFiles/_opnav_camera.dir/all] Error 2
make: *** [all] Error 2
Looking around online, it looks like I'm not successfully linking the library. I'm new to CMake, so I have no idea what I'm doing.
I've added the following to my CMakelists.txt:
#SQLite 3
# Look for the header file.
FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h)
# Look for the library.
FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3.0)
# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR)
# Copy the results to the output variables.
IF(SQLITE3_FOUND)
SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY})
SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR})
message( " Found ")
ELSE(SQLITE3_FOUND)
SET(SQLITE3_LIBRARIES)
SET(SQLITE3_INCLUDE_DIRS)
ENDIF(SQLITE3_FOUND)
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
CMake is finding the library, but I think I'm just missing a step in how to actually link it. enter image description here
What piece am I missing?
Upvotes: 0
Views: 681
Reputation: 56
ld: symbol(s) not found for architecture x86_64
It appears you are building a 64 bit application and attempting to link against a 32 bit library. You will need to link against the 64 bit version of the library instead.
Upvotes: 1