PCL make error: Undefined symbols for architecture x86_64 #pcl - c++

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})

Related

cMakefile for using tesseract and opencv

I am a newbie to cmake and I am writing an application for using tesseract. the g++ command line work fine
g++ -O3 -std=c++11 `pkg-config --cflags --libs tesseract opencv` my_first.cpp -o my_first
But I wrote the following CMakeFile.txt and building in Clion and it throws a bunch of linking errors
cmake_minimum_required(VERSION 2.6)
add_compile_options(-std=c++11)
project (my_first)
find_package(PkgConfig REQUIRED)
pkg_check_modules (OPENCV REQUIRED opencv)
link_directories(${OPENCV_LIBRARY_DIRS})
pkg_check_modules (TESSERACT REQUIRED tesseract)
link_directories(${TESSERACT_LIBRARY_DIRS})
add_executable(myfirst my_first.cpp)
The following is the error thrown
/usr/local/Cellar/cmake/3.11.3/bin/cmake --build
/Users/ggovindan/tessaract_ocr/tesseract/experiments/cmake-build-debug --target all -- -j 4
[ 50%] Linking CXX executable myfirst
Undefined symbols for architecture x86_64:
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in my_first.cpp.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in my_first.cpp.o
cv::String::operator=(cv::String const&) in my_first.cpp.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&) in
my_first.cpp.o
"cv::imread(cv::String const&, int)", referenced from:
_main in my_first.cpp.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in my_first.cpp.o
"tesseract::TessBaseAPI::GetUTF8Text()", referenced from:
_main in my_first.cpp.o
"tesseract::TessBaseAPI::SetPageSegMode(tesseract::PageSegMode)", referenced from:
_main in my_first.cpp.o
"tesseract::TessBaseAPI::Init(char const*, char const*,
tesseract::OcrEngineMode, char**, int, GenericVector<STRING> const*,
GenericVector<STRING> const*, bool)", referenced from:
tesseract::TessBaseAPI::Init(char const*, char const*,
tesseract::OcrEngineMode) in my_first.cpp.o
"tesseract::TessBaseAPI::SetImage(unsigned char const*, int, int, int, int)", referenced from:
_main in my_first.cpp.o
"tesseract::TessBaseAPI::TessBaseAPI()", referenced from:
_main in my_first.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]: *** [myfirst] Error 1
make[1]: *** [CMakeFiles/myfirst.dir/all] Error 2
make: *** [all] Error 2
This is what you need to do.Let me know if you face any problems.
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package( PkgConfig REQUIRED)
pkg_search_module( TESSERACT REQUIRED tesseract )
pkg_search_module( LEPTONICA REQUIRED lept )
include_directories( ${TESSERACT_INCLUDE_DIRS} )
include_directories( ${LEPTONICA_INCLUDE_DIRS} )
link_directories( ${TESSERACT_LIBRARY_DIRS} )
link_directories( ${LEPTONICA_LIBRARY_DIRS} )
find_package( OpenCV REQUIRED )
include_directories("myfirst.h")
file(GLOB SOURCES "myfirst.cpp")
add_executable(myfirst ${SOURCES})
target_link_libraries( myfirst ${OpenCV_LIBS} )
target_link_libraries( myfirst ${TESSERACT_LIBRARIES} )
target_link_libraries( myfirst ${LEPTONICA_LIBRARIES} )
#install
install(TARGETS myfirst DESTINATION /usr/local/bin)

Linking errors when building c++ project using mongo-cxx-driver

I am currently developing a C++ application which requires the use of the mongo-cxx-driver for accessing a MongoDB instance. I attempted a couple of methods of installation, and am met with the same linker issues each time.
Initially, I attempted to install mongo-cxx-drivers and mongod-c-driver as detailed here: https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/
Using the following portion of my CMake configuration, I was able to get auto-completion working and my IDE to recognize the libraries:
. . .
set(CMAKE_CXX_STANDARD 17)
set(BUILD_DIR "cmake-build-debug")
set(BUILD_PATH "${CMAKE_SOURCE_DIR}/${BUILD_DIR}")
find_package(libmongocxx REQUIRED)
find_package(libbsoncxx REQUIRED)
message("LIBMONGOCXX_INCLUDE_DIRS = ${LIBMONGOCXX_INCLUDE_DIRS}")
message("LIBMONGOCXX_LIBRARIES = ${LIBMONGOCXX_LIBRARIES}")
message("LIBBSONCXX_INCLUDE_DIRS = ${LIBBSONCXX_INCLUDE_DIRS}")
message("LIBBSONCXX_LIBRARIES = ${LIBBSONCXX_LIBRARIES}")
file(GLOB COMMON_LIBRARIES ${LIBMONGOCXX_LIBRARIES} ${LIBBSONCXX_LIBRARIES})
SET(APP_SOURCE source/App/main.cpp)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_PATH}/App)
add_executable(App ${APP_SOURCE})
target_include_directories(App PUBLIC ${LIBMONGOCXX_INCLUDE_DIRS})
target_include_directories(App PUBLIC ${LIBBSONCXX_INCLUDE_DIRS})
target_link_libraries(App ${COMMON_LIBRARIES})
. . .
Unfortunately during the linking stage, I get these errors:
[100%] Linking CXX executable App/App
Undefined symbols for architecture x86_64:
"mongocxx::v_noabi::uri::uri(bsoncxx::v_noabi::string::view_or_value)", referenced from:
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
"mongocxx::v_noabi::uri::~uri()", referenced from:
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
"mongocxx::v_noabi::client::client(mongocxx::v_noabi::uri const&, mongocxx::v_noabi::options::client const&)", referenced from:
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
"mongocxx::v_noabi::client::~client()", referenced from:
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in .cpp.o
"mongocxx::v_noabi::instance::instance()", referenced from:
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
"mongocxx::v_noabi::instance::~instance()", referenced from:
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) 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]: *** [App/App] Error 1
make[2]: *** [CMakeFiles/App.dir/all] Error 2
make[1]: *** [CMakeFiles/App.dir/rule] Error 2
make: *** [App] Error 2
I tried building using different c++17 polyfills just in case, no go. I also tried manually uninstalling mongo-cxx-driver and mongo-c-driver this time installing thru homebrew, but was met with the same errors.
In my research, the most relatable StackOverflow post is Using the mongodb cxx driver in a cmake c++ project, yet none of the solutions there work for me.
Operating System: macOS Sierra 10.12.6
IDE: CLion 2017.2.2 Build #CL-172.3968.17, built on August 22, 2017
CMake: 3.8.2
mongo-cxx-driver: 3.1.3
mongo-c-driver: 1.8.0
Any help or insight would be much appreciated, please feel free to ask me to clarify or add information where it may be unclear or missing.
EDIT: Here is the code which is causing the error:
#include <cstdint>
#include <iostream>
#include <vector>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/stdx.hpp>
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::open_document;
mongocxx::instance instance{}; // This should be done only once.
mongocxx::uri uri("mongodb://localhost:27017");
mongocxx::client client(uri);
EDIT: I went ahead and created a simple project from scratch and went through all the steps again just to be sure I didn't flub anything. Still in the same boat at the end though.
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/user000/Projects/mongo-cxx-driver-test
-- CMAKE_SOURCE_DIR: /Users/user000/Projects/mongo-cxx-driver-test
-- BUILD_PATH: /Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug
LIBMONGOCXX_INCLUDE_DIRS = /usr/local/include/mongocxx/v_noabi
LIBMONGOCXX_LIBRARIES = mongocxx
LIBBSONCXX_INCLUDE_DIRS = /usr/local/include/bsoncxx/v_noabi
LIBBSONCXX_LIBRARIES = bsoncxx
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug
[Finished]
Here is the full output when building with verbose mode enabled for CMake:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug --target App -- -j 2
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H/Users/user000/Projects/mongo-cxx-driver-test -B/Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 App
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H/Users/user000/Projects/mongo-cxx-driver-test -B/Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start /Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug/CMakeFiles 2
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 CMakeFiles/App.dir/all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/App.dir/build.make CMakeFiles/App.dir/depend
cd /Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /Users/user000/Projects/mongo-cxx-driver-test /Users/user000/Projects/mongo-cxx-driver-test /Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug /Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug /Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug/CMakeFiles/App.dir/DependInfo.cmake --color=
Scanning dependencies of target App
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/App.dir/build.make CMakeFiles/App.dir/build
[ 50%] Building CXX object CMakeFiles/App.dir/source/App/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/bsoncxx/v_noabi -g -std=gnu++1z -o CMakeFiles/App.dir/source/App/main.cpp.o -c /Users/user000/Projects/mongo-cxx-driver-test/cmake-build-debug/source/App/main.cpp
[100%] Linking CXX executable App
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/App.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/App.dir/source/App/main.cpp.o -o App
Undefined symbols for architecture x86_64:
"mongocxx::v_noabi::uri::uri(bsoncxx::v_noabi::string::view_or_value)", referenced from:
_main in main.cpp.o
"mongocxx::v_noabi::uri::~uri()", referenced from:
_main in main.cpp.o
"mongocxx::v_noabi::client::client(mongocxx::v_noabi::uri const&, mongocxx::v_noabi::options::client const&)", referenced from:
_main in main.cpp.o
"mongocxx::v_noabi::client::~client()", referenced from:
_main in main.cpp.o
"mongocxx::v_noabi::instance::instance()", referenced from:
_main in main.cpp.o
"mongocxx::v_noabi::instance::~instance()", 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]: *** [App] Error 1
make[2]: *** [CMakeFiles/App.dir/all] Error 2
make[1]: *** [CMakeFiles/App.dir/rule] Error 2
make: *** [App] Error 2
The full CMakeLists.txt:
cmake_minimum_required(VERSION 3.8)
project(App)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE on)
set(BUILD_DIR "cmake-build-debug")
set(BUILD_PATH "${CMAKE_SOURCE_DIR}/${BUILD_DIR}")
set(BUILD_DIR "cmake-build-debug")
set(BUILD_PATH "${CMAKE_SOURCE_DIR}/${BUILD_DIR}")
message(STATUS "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
message(STATUS "BUILD_PATH: ${BUILD_PATH}")
find_package(libmongocxx REQUIRED)
find_package(libbsoncxx REQUIRED)
message("LIBMONGOCXX_INCLUDE_DIRS = ${LIBMONGOCXX_INCLUDE_DIRS}")
message("LIBMONGOCXX_LIBRARIES = ${LIBMONGOCXX_LIBRARIES}")
message("LIBBSONCXX_INCLUDE_DIRS = ${LIBBSONCXX_INCLUDE_DIRS}")
message("LIBBSONCXX_LIBRARIES = ${LIBBSONCXX_LIBRARIES}")
file(GLOB COMMON_LIBRARIES ${LIBMONGOCXX_LIBRARIES} ${LIBBSONCXX_LIBRARIES})
set(SOURCE_FILES cmake-build-debug/source/App/main.cpp)
add_executable(App ${SOURCE_FILES})
target_include_directories(App PUBLIC ${LIBMONGOCXX_INCLUDE_DIRS})
target_include_directories(App PUBLIC ${LIBBSONCXX_INCLUDE_DIRS})
target_link_libraries(App ${COMMON_LIBRARIES})
The code producing the errors:
#include <cstdint>
#include <iostream>
#include <vector>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/stdx.hpp>
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::open_document;
int main() {
std::cout << "Hello, World!" << std::endl;
mongocxx::instance instance{}; // This should be done only once.
mongocxx::uri uri("mongodb://localhost:27017");
mongocxx::client client(uri);
return 0;
}
Turns out I was using CMake's GLOB wrong.
Changing
target_link_libraries(App ${COMMON_LIBRARIES})
to
target_link_libraries(App ${LIBMONGOCXX_LIBRARIES} ${LIBBSONCXX_LIBRARIES})
fixed the issue.

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})

Multiples CMake in a project

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

Compling a code sample in OpenCV 2.4.6.1 using CMake in MacOSX Mavericks

I was working on some computer vision code with OpenCV, and wanted to try running OpenCV by compiling the OpenCV tutorial code using CMake. When I tried to compile and run the basic display_image program, it compiled successfully and ran(I added a CMakeLists.txt file and ran cmake . and then make in Terminal. However, when I applied the same procedure to run a few other programs, it didn't work.
I got the following error message
$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/censam/OpenCV/Vision Code/Examples/grabcut
$ make
Linking CXX executable grabcut
Undefined symbols for architecture x86_64:
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, >
std::__1::allocator<char> > const&, int)", referenced from:
_main in grabcut.cpp.o
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, >
std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
GCApplication::showImage() const in grabcut.cpp.o
"cv::Exception::Exception(int, std::__1::basic_string<char, std::__1::char_traits<char>, >
std::__1::allocator<char> > const&, std::__1::basic_string<char, >
std::__1::char_traits<char>, std::__1::allocator<char> > const&, >
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >
const&, int)", referenced from:
getBinMask(cv::Mat const&, cv::Mat&) in grabcut.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]: *** [grabcut] Error 1
make[1]: *** [CMakeFiles/grabcut.dir/all] Error 2
make: *** [all] Error 2
My CMakeLists.txt file is as follows:
cmake_minimum_required(VERSION 2.8)
project( grabcut )
find_package( OpenCV REQUIRED )
add_executable( grabcut grabcut.cpp )
target_link_libraries( grabcut ${OpenCV_LIBS} )
May I know why this happens?I suspect it could be because CMake hasn't linked the required libraries during compiling. When I tried this with XCode, I got the same result, but I prefer to use CMake so that I can port my code over to linux systems more easily.
I found the following link Linking OpenCV 2.3 program in Mac OS X Lion: symbol(s) not found for architecture x86_64 also had the same problem, but the issue doesn't seem to have been resolved.
Any help on how I can get my program to compile and run using CMake in OSX Mavericks will be much appreciated.
Change the compiler from clang to g++-4.2.
A more detailed explain could be find here.