Multiples CMake in a project - c++

I'm developing a C++ application that use a library that i develop before. I don`t want link the binary to my new project because who use another plataform need rebuild then. So, i whant attach the cmake file from this another project to this new one and when i build then, build the library too. Someone know how i do this? Thanks Alot.
String Library: https://github.com/TigreFramework/String
My new CMake file:
cmake_minimum_required(VERSION 3.4)
project(DataBase)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp DataBase.cpp DataBase.h String.h libString.a)
add_executable(DataBase ${SOURCE_FILES})
EDIT 01:
Now i can compile with this CMake:
cmake_minimum_required(VERSION 3.4)
project(String)
include_directories(./include/cryptopp563/)
#link_directories(./include/cryptopp563/)
add_subdirectory(./include/cryptopp563/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_library(cryptopp include/cryptopp563/)
set(SOURCE_FILES main.cpp String.cpp String.h RsaString.cpp RsaString.h)
add_library(RsaString STATIC RsaString.cpp)
add_library(String STATIC String.cpp)
#add_executable(Teste ${SOURCE_FILES})
But, if i use de add_executable i receive this error:
[ 1%] Built target String
[ 2%] Built target RsaString
[ 2%] Linking CXX executable Teste
[ 97%] Built target cryptopp
Undefined symbols for architecture x86_64:
"CryptoPP::RandomPool::IncorporateEntropy(unsigned char const*, unsigned long)", referenced from:
vtable for CryptoPP::AutoSeededRandomPool in String.cpp.o
"CryptoPP::RandomPool::GenerateIntoBufferedTransformation(CryptoPP::BufferedTransformation&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long)", referenced from:
vtable for CryptoPP::AutoSeededRandomPool in String.cpp.o
"CryptoPP::RandomPool::RandomPool()", referenced from:
CryptoPP::AutoSeededRandomPool::AutoSeededRandomPool(bool, unsigned int) in String.cpp.o
.............. MORE LINES HIDEM HERE .................
"non-virtual thunk to CryptoPP::BufferedTransformation::GetWaitObjects(CryptoPP::WaitObjectContainer&, CryptoPP::CallStack const&)", referenced from:
vtable for CryptoPP::SourceTemplate<CryptoPP::FileStore> in RsaString.cpp.o
vtable for CryptoPP::FileSource in RsaString.cpp.o
vtable for CryptoPP::AutoSignaling<CryptoPP::InputRejecting<CryptoPP::BufferedTransformation> > in RsaString.cpp.o
vtable for CryptoPP::InputRejecting<CryptoPP::BufferedTransformation> in RsaString.cpp.o
vtable for CryptoPP::InputRejecting<CryptoPP::Filter> in RsaString.cpp.o
vtable for CryptoPP::Sink in RsaString.cpp.o
vtable for CryptoPP::PK_DecryptorFilter in RsaString.cpp.o
...
"non-virtual thunk to CryptoPP::BufferedTransformation::GetMaxWaitObjectCount() const", referenced from:
vtable for CryptoPP::SourceTemplate<CryptoPP::FileStore> in RsaString.cpp.o
vtable for CryptoPP::FileSource in RsaString.cpp.o
vtable for CryptoPP::AutoSignaling<CryptoPP::InputRejecting<CryptoPP::BufferedTransformation> > in RsaString.cpp.o
vtable for CryptoPP::InputRejecting<CryptoPP::BufferedTransformation> in RsaString.cpp.o
vtable for CryptoPP::InputRejecting<CryptoPP::Filter> in RsaString.cpp.o
vtable for CryptoPP::Sink in RsaString.cpp.o
vtable for CryptoPP::PK_DecryptorFilter in RsaString.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)
CMakeFiles/Teste.dir/build.make:146: recipe for target 'Teste' failed
gmake[2]: *** [Teste] Error 1
CMakeFiles/Makefile2:141: recipe for target 'CMakeFiles/Teste.dir/all' failed
gmake[1]: *** [CMakeFiles/Teste.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
gmake: *** [all] Error 2

You can use add_subdirectory https://cmake.org/cmake/help/v3.0/command/add_subdirectory.html
or simple include
https://cmake.org/cmake/help/v3.0/command/include.html
also there is feature of cmake called external project,
which allow you to build project with any build system
https://cmake.org/cmake/help/v3.0/module/ExternalProject.html

Related

Unable to build my-sql-connector-c++ with CMake

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

PCL make error: Undefined symbols for architecture x86_64 #pcl

No error using cmake ..
Error occurs when make as following:
Scanning dependencies of target environment
[ 25%] Building CXX object CMakeFiles/environment.dir/src/environment.cpp.o
[ 50%] Building CXX object CMakeFiles/environment.dir/src/render/render.cpp.o
[ 75%] Building CXX object CMakeFiles/environment.dir/src/processPointClouds.cpp.o
[100%] Linking CXX executable environment
Undefined symbols for architecture x86_64:
"pcl::visualization::createLine(Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&)", referenced from:
bool pcl::visualization::PCLVisualizer::addLine<pcl::PointXYZ, pcl::PointXYZ>(pcl::PointXYZ const&, pcl::PointXYZ const&, double, double, double, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) in render.cpp.o
"pcl::visualization::PCLVisualizer::removeShape(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
clearRays(boost::shared_ptr<pcl::visualization::PCLVisualizer>&) in render.cpp.o
"pcl::visualization::PCLVisualizer::updateCells(vtkSmartPointer<vtkIdTypeArray>&, vtkSmartPointer<vtkIdTypeArray>&, long long)", referenced from:
...
...
...
...
_main in environment.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]: *** [environment] Error 1
make[1]: *** [CMakeFiles/environment.dir/all] Error 2
make: *** [all] Error 2
The cmakelists.txt are
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
add_definitions(-std=c++11)
set(CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS, "${CXX_FLAGS}")
project(playback)
find_package(PCL 1.2 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
add_executable (environment src/environment.cpp src/render/render.cpp src/processPointClouds.cpp)
target_link_libraries (environment ${PCL_LIBRARIES})
OS
mac catarina
PCL 1.9
xcode
The problem should be related to cmakelists.txt such as library links, but I have no any ideas to locate and fix it.
Solved by linking libraries:
find_package(PCL 1.3 REQUIRED COMPONENT common io VISUALIZATION)
target_link_libraries (environment ${PCL_LIBRARIES} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES} ${PCL_VISUALIZATION_LIBRARIES})

Updating CMake (seems to have) broke my program

I updated from CMake 3.6 to whatever the latest version is (3.12.0-rc2) and now one of my programs won't compile.
The weird thing is, the error message shows undefined symbols from in the standard library itself. Here's the error message:
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(char const*)", referenced from:
GetName() in ncc.cpp.o
Expression() in ncc.cpp.o
Term() in ncc.cpp.o
GetNum() in ncc.cpp.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string()", referenced from:
GetName() in ncc.cpp.o
GetNum() in ncc.cpp.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator+=(char)", referenced from:
GetName() in ncc.cpp.o
GetNum() in ncc.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]: *** [ncc] Error 1
make[1]: *** [CMakeFiles/ncc.dir/all] Error 2
make: *** [all] Error 2
How do I fix this? Do I need to link to a different version of the standard library? And if so, how I tell CMake that?
Here's my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.0)
project(ncc)
add_definitions(-std=c++14)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/)
add_executable(ncc ${CompSource})
add_executable(ncc-opt ${OptSource})
add_executable(nci ${IntSource})
I tried it with the add_definitions line and without it, which didn't seem to make a difference.
This is the relevant output from running make VERBOSE=1:
Scanning dependencies of target ncc
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/ncc.dir/build.make CMakeFiles/ncc.dir/build
[ 83%] Building CXX object CMakeFiles/ncc.dir/src/ncc.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -std=c++14 -o CMakeFiles/ncc.dir/src/ncc.cpp.o -c /Users/nepps/Dropbox/Projects/ncc/src/ncc.cpp
[100%] Linking CXX executable ncc
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/ncc.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/ncc.dir/src/ncc.cpp.o -o ncc
Undefined symbols for architecture x86_64:
(same errors as above)
Feel free to comment if you need more information. I'm using a MacBook pro running MacOS 10.13.3.
Well, I'm not sure why it worked, but all of the functions in the program were marked static and removing that made the errors go away. Go figure.

CMake finds boost libraries but Make fails to link them

After coming back to a project after a month I am able to run CMake successfully with the following output
-- Boost version: 1.61.0
-- Found the following Boost libraries:
-- system
-- thread
-- filesystem
-- chrono
-- date_time
-- atomic
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/LittleNewt/gitness/MangaMeCLI/build
but for some reason when running Make on the generated MakeFile I get the following output
[ 50%] Building CXX object CMakeFiles/mangaMeCLI.dir/src/mangaMeCLI.cpp.o
[100%] Linking CXX executable mangaMeCLI
Undefined symbols for architecture x86_64:
"boost::filesystem::path::operator/=(char const*)", referenced from:
_main in mangaMeCLI.cpp.o
"boost::filesystem::path::operator/=(boost::filesystem::path const&)", referenced from:
boost::filesystem::path::operator/=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in mangaMeCLI.cpp.o
boost::filesystem::path::operator/=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mangaMeCLI.cpp.o
"boost::filesystem::detail::current_path(boost::system::error_code*)", referenced from:
boost::filesystem::current_path() in mangaMeCLI.cpp.o
"boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::create_directory(boost::filesystem::path const&) in mangaMeCLI.cpp.o
"boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::exists(boost::filesystem::path const&) in mangaMeCLI.cpp.o
boost::filesystem::is_directory(boost::filesystem::path const&) in mangaMeCLI.cpp.o
"boost::system::system_category()", referenced from:
___cxx_global_var_init.75 in mangaMeCLI.cpp.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init.73 in mangaMeCLI.cpp.o
___cxx_global_var_init.74 in mangaMeCLI.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]: *** [mangaMeCLI] Error 1
make[1]: *** [CMakeFiles/mangaMeCLI.dir/all] Error 2
make: *** [all] Error 2
I did some research and have found others having the same issues due to not linking the correct version of the libraries for there architecture (64bit vs 32bit) but am not sure how to identify if this is the issue for me.
Here is my unchanged CMakeLists.txt file
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.1)
PROJECT(MangaMeCLI)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
INCLUDE_DIRECTORIES(includes)
ADD_EXECUTABLE(mangaMeCLI src/mangaMeCLI.cpp)
MESSAGE("${CMAKE_CXX_FLAGS}")
SET(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost REQUIRED COMPONENTS system thread filesystem)
INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mangaMeCLI ${BOOST_LIBRARIES})
SET(OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*)
FIND_PACKAGE(OpenSSL REQUIRED)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(mangaMeCLI ${OPENSSL_LIBRARIES})
FIND_PACKAGE(cppnetlib REQUIRED)
INCLUDE_DIRECTORIES(${CPPNETLIB_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mangaMeCLI ${CPPNETLIB_LIBRARIES})
After reading a useful comment I found that the BOOST_LIBRARIES variable was empty even though cmake prints that it found the boost libraries I was looking for. I am assuming this is the reason for my error.
CMake variables are case-sensitive. As per the find module's documentation, you want Boost_LIBRARIES, not BOOST_LIBRARIES:
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mangaMeCLI ${Boost_LIBRARIES})

cMake txt file for linking glfw library

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