Introduction
I am trying to connect and interact with a mysql db running on my local, in a c++ project. I am also using cmake to compile my project.
Preparation
I installed mysqlconnector cpp by using mysql-connector-odbc-8.0.25-macos11-x86-64bit.dmg from their community downloads. I have the include and lib files available at /usr/local/mysql-connector-c+
CmakeLists.txt
Part of my CMakeLists.txt which deals with mysqlconnector is referenced below:
cmake_minimum_required(VERSION 3.13.4 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 11)
set(FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR "/usr/local/mysql-connector-c++")
include_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/include)
link_directories(${FULL_PATH_TO_MYSQL_CONNECTOR_CPP_DIR}/lib64)
add_executable(runservice main.cpp)
target_link_libraries(runservice mysqlcppconn)
The cmake command runs fine.
Build Error
When I try to build using '''make``` command, I get the following error :
Undefined symbols for architecture x86_64:
"mysqlx::abi2::r0::common::Value::print(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const", referenced from:
mysqlx::abi2::r0::Value::print(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in main.cpp.o
construction vtable for mysqlx::abi2::r0::common::Value-in-mysqlx::abi2::r0::Value in main.cpp.o
"typeinfo for mysqlx::abi2::r0::common::Value", referenced from:
construction vtable for mysqlx::abi2::r0::common::Value-in-mysqlx::abi2::r0::Value in main.cpp.o
typeinfo for mysqlx::abi2::r0::Value in main.cpp.o
"vtable for mysqlx::abi2::r0::DbDoc", referenced from:
mysqlx::abi2::r0::Value::~Value() in main.cpp.o
__GLOBAL__sub_I_main.cpp in main.cpp.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
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]: *** [runservice] Error 1
make[1]: *** [CMakeFiles/runservice.dir/all] Error 2
make: *** [all] Error 2
I can't understand this error or how to go about solving this.
Thank you for your precious time
Related
I have created a small C++ SDL2 project with CMake under macOS Big Sur (m1).
This is the CMakeLists.txt:
cmake_minimum_required(VERSION 3.22.2)
project(sdl2gamepad)
add_library(sdl2lib SHARED IMPORTED)
set_property(TARGET sdl2lib PROPERTY IMPORTED_LOCATION "/opt/homebrew/lib/libSDL2.dylib")
include_directories("/opt/homebrew/include")
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ${sdl2lib})
I installed SDL2 and CMake with homebrew.
The project was initially compiled and linked with the Makefile without problems and I was able to run it.
I then wanted to structure my project with an src and build folder and had adapted the CMakeLists.txt. Unfortunately, CMake/Make was no longer able to link the SDL2 lib.
Linking error message:
[ 50%] Linking CXX executable sdl2gamepad
Undefined symbols for architecture arm64:
"_SDL_CreateWindow", referenced from:
_main in main.cpp.o
"_SDL_DestroyWindow", referenced from:
_main in main.cpp.o
"_SDL_GetError", referenced from:
_main in main.cpp.o
"_SDL_GetWindowSurface", referenced from:
_main in main.cpp.o
"_SDL_Init", referenced from:
_main in main.cpp.o
"_SDL_LoadBMP_RW", referenced from:
_main in main.cpp.o
"_SDL_PollEvent", referenced from:
_main in main.cpp.o
"_SDL_Quit", referenced from:
_main in main.cpp.o
"_SDL_RWFromFile", referenced from:
_main in main.cpp.o
"_SDL_UpdateWindowSurface", referenced from:
_main in main.cpp.o
"_SDL_UpperBlit", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [sdl2gamepad] Error 1
make[1]: *** [CMakeFiles/sdl2gamepad.dir/all] Error 2
make: *** [all] Error 2
I then reset the CMakeLists.txt to the status where it had worked (code above). But unfortunately, the problem still exists.
But I can compile the code with this command, it is probably due to a CMake misconfiguration.
$ clang++ main.cpp -o main /opt/homebrew/lib/libSDL2.dylib -I /opt/homebrew/include
CMake Version is 3.22.2.
SDL2 Version is 2.0.20.
Many thanks for your help!
I am new to using CLion and am trying to build my first project. I have two source files (main.cpp and Hero.cpp) and a header for Hero.cpp. At the top of Hero.cpp there is a yellow banner that reads "This file does not belong to any project target; code insight features might not work properly." I am pretty sure there are no mistakes with regard to the syntax or logic of the program. However, when I try to run my code, I get:
[ 50%] Building CXX object CMakeFiles/untitled.dir/main.cpp.o
[100%] Linking CXX executable untitled
Undefined symbols for architecture x86_64:
"Hero::GetStrength()", referenced from:
PrintHero(Hero) in main.cpp.o
"Hero::GetHitpoints()", referenced from:
PrintHero(Hero) in main.cpp.o
"Hero::GetName()", referenced from:
PrintHero(Hero) in main.cpp.o
"Hero::Hero(std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> >, int, int)", referenced from:
_main in main.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[3]: *** [untitled] Error 1
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
make: *** [untitled] Error 2
Could somebody help me figure out this problem? Thanks in advance!
I am working on a little software that needed a small server that listens to http requests. Unfortunately, the productive server uses https only, so the requests fail. I've search the web and found this example: http://www.boost.org/doc/libs/1_65_0/doc/html/boost_asio/example/cpp03/ssl/server.cpp
I tried my best to apply the required changes. But I can't compile it. I am on a MacOS machine, but the Server is a Ubuntu Server. I installed OpenSSL via brew.
The compilation fails at the linking process:
[ 98%] Linking CXX executable GpdServer
Undefined symbols for architecture x86_64:
"_ERR_remove_thread_state", referenced from:
boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in main.cpp.o
boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in TcpServer.cpp.o
boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in TcpConnection.cpp.o
"_TLSv1_1_client_method", referenced from:
boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
"_TLSv1_1_method", referenced from:
boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
"_TLSv1_1_server_method", referenced from:
boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
"_TLSv1_2_client_method", referenced from:
boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
"_TLSv1_2_method", referenced from:
boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.cpp.o
"_TLSv1_2_server_method", referenced from:
boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in TcpServer.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]: *** [GpdServer] Error 1
make[1]: *** [CMakeFiles/GpdServer.dir/all] Error 2
make: *** [all] Error 2
The TcpConnection files that cause this issue are here:
https://github.com/cwansart/gpd/blob/master/src/TcpServer.h
https://github.com/cwansart/gpd/blob/master/src/TcpServer.cpp
My build system is CMake. Including it works fine.
What am I doing wrong? How do I fix this?
As it turns out the macOS was the issue. I installed OpenSSL via brew. First, my CLion/CMake didn't find it, so I added an if to check if its an Apple PC. In that case I set the path manually to the path brew gave me. Now, for some reason the linking doesn't work.
On Linux with libssl-dev there are no issues.
I'm trying to install mydumper but the make step complains about undefine symbols. I've searched other questions where they talk about linking your object file to make sure the compiler can find the methods it needs. However this is just plain installation and I am not a C guy. Any pointer is highly appreciated. Here's the error I am seeing:
[ 16%] Linking C executable myloader
Undefined symbols for architecture x86_64:
"_CFRelease", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_CFStringGetCString", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_CFStringGetCStringPtr", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_CFStringGetLength", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_CFURLCopyFileSystemPath", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_CFURLCreateFromFSRef", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"_FSFindFolder", referenced from:
_find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
"std::terminate()", referenced from:
___clang_call_terminate in libmysqlclient.a(ssl.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]: *** [myloader] Error 1
make[1]: *** [CMakeFiles/myloader.dir/all] Error 2
make: *** [all] Error 2
I'm learning about c++ by following a tutorial, I'm using cMake right now and I have my glfw library in my external folder but I can't get it to link correctly. Here is my cMake txt file
cmake_minimum_required(VERSION 2.8.4)
project(dunjun)
set(dunjun_src src/main.cpp)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES src/main.cpp)
include_directories(
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/external/glfw-3.1/include
)
link_directories(
${PROJECT_SOURCE_DIR}/external/glfw-3.1/src
)
add_executable(dunjun ${dunjun_src})
target_link_libraries(dunjun ${PROJECT_SOURCE_DIR}/external/glfw-3.1/src)
The errors it gives me are the following.
[100%] Building CXX object CMakeFiles/dunjun.dir/src/main.cpp.o
Linking CXX executable dunjun
Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
_main in main.cpp.o
"_glfwInit", referenced from:
_main in main.cpp.o
"_glfwMakeContextCurrent", referenced from:
_main in main.cpp.o
"_glfwPollEvents", referenced from:
_main in main.cpp.o
"_glfwSwapBuffers", referenced from:
_main in main.cpp.o
"_glfwTerminate", referenced from:
_main in main.cpp.o
"_glfwWindowShouldClose", referenced from:
_main in main.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[3]: *** [dunjun] Error 1
make[2]: *** [CMakeFiles/dunjun.dir/all] Error 2
make[1]: *** [CMakeFiles/dunjun.dir/rule] Error 2
make: *** [dunjun] Error 2