I made a working C++ project with boost and std on windows with visual studio.
After some hours of coding I realise that was stupide of me to use a VS2017 since I will need to test the software on mac and linux.
So I went on my mac, and now I am trying to just compile everything.
I built boost on mac :
./bootstrap.sh && ./b2 threading=multi link=static
runtime-link=static install
Then I took the lib I need (chrono, thread, regex, system, thread, date_time) and copy the libboost_xxx.a files into a folder of my project.
Now this is my current makefile :
cmake_minimum_required(VERSION 3.8)
project(AuthServer)
include_directories(${CMAKE_SOURCE_DIR}/Include)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES
AuthServer/Client.cpp
AuthServer/Client.h
AuthServer/main.cpp
AuthServer/NetworkManager.cpp
AuthServer/NetworkManager.h)
find_library(BOOST_LIBRARY
NAMES libboost_atomic boost_chrono boost_date_time boost_regex boost_thread boost_system
PATHS ${CMAKE_SOURCE_DIR}/Lib/mac/x64
NO_DEFAULT_PATH)
add_executable(AuthServer ${SOURCE_FILES})
target_link_libraries(AuthServer ${BOOST_LIBRARY})
As you can see I don't have much going on but nonetheless it cannot be built :
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug"
--target AuthServer -- -j 4 /Applications/CLion.app/Contents/bin/cmake/bin/cmake
-H"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer" -B"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug"
--check-build-system CMakeFiles/Makefile.cmake 0 /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 AuthServer /Applications/CLion.app/Contents/bin/cmake/bin/cmake
-H"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer" -B"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug"
--check-build-system CMakeFiles/Makefile.cmake 0 /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug/CMakeFiles" 4 /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 CMakeFiles/AuthServer.dir/all /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/AuthServer.dir/build.make CMakeFiles/AuthServer.dir/depend cd "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug" && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer" "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer" "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug" "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug" "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/cmake-build-debug/CMakeFiles/AuthServer.dir/DependInfo.cmake"
--color= /Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/AuthServer.dir/build.make CMakeFiles/AuthServer.dir/build [ 25%] Building CXX object CMakeFiles/AuthServer.dir/AuthServer/Client.cpp.o [ 50%] Building CXX object CMakeFiles/AuthServer.dir/AuthServer/main.cpp.o /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-I"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/Include" -g -arch x86_64
-mmacosx-version-min=10.12 -std=gnu++11 -o CMakeFiles/AuthServer.dir/AuthServer/Client.cpp.o -c "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/AuthServer/Client.cpp" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-I"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/Include" -g -arch x86_64
-mmacosx-version-min=10.12 -std=gnu++11 -o CMakeFiles/AuthServer.dir/AuthServer/main.cpp.o -c "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/AuthServer/main.cpp" [ 75%] Building CXX object CMakeFiles/AuthServer.dir/AuthServer/NetworkManager.cpp.o /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-I"/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/Include" -g -arch x86_64
-mmacosx-version-min=10.12 -std=gnu++11 -o CMakeFiles/AuthServer.dir/AuthServer/NetworkManager.cpp.o -c "/Users/rxp/Code Project/MagesBattleAuthServerCPP/AuthServer/AuthServer/NetworkManager.cpp" [100%] Linking CXX executable AuthServer /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/AuthServer.dir/link.txt --verbose=1 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-g -arch x86_64 -mmacosx-version-min=10.12 -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/AuthServer.dir/AuthServer/Client.cpp.o CMakeFiles/AuthServer.dir/AuthServer/main.cpp.o CMakeFiles/AuthServer.dir/AuthServer/NetworkManager.cpp.o -o AuthServer ../Lib/mac/x64/libboost_chrono.a Undefined symbols for architecture x86_64: "boost::this_thread::interruption_point()", referenced from:
boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in NetworkManager.cpp.o "boost::this_thread::disable_interruption::disable_interruption()", referenced from:
boost::shared_mutex::lock_shared() in NetworkManager.cpp.o
boost::shared_mutex::lock() in NetworkManager.cpp.o "boost::this_thread::disable_interruption::~disable_interruption()", referenced from:
boost::shared_mutex::lock_shared() in NetworkManager.cpp.o
boost::shared_mutex::lock() in NetworkManager.cpp.o "boost::detail::thread_data_base::~thread_data_base()", referenced from:
boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf1<void, NetworkManager, boost::shared_ptr<boost::asio::io_service> >, boost::_bi::list2<boost::_bi::value<NetworkManager*>, boost::_bi::value<boost::shared_ptr<boost::asio::io_service> > > >
>::~thread_data() in NetworkManager.cpp.o "boost::detail::get_current_thread_data()", referenced from:
boost::detail::interruption_checker::interruption_checker(_opaque_pthread_mutex_t*,
_opaque_pthread_cond_t*) in NetworkManager.cpp.o "boost::system::system_category()", referenced from:
boost::asio::error::get_system_category() in Client.cpp.o
boost::system::error_code::error_code() in Client.cpp.o
___cxx_global_var_init.2 in Client.cpp.o
boost::asio::error::get_system_category() in main.cpp.o
___cxx_global_var_init.2 in main.cpp.o
boost::asio::error::get_system_category() in NetworkManager.cpp.o
boost::system::error_code::error_code() in NetworkManager.cpp.o
... "boost::system::generic_category()", referenced from:
boost::system::error_category::std_category::equivalent(int, std::__1::error_condition const&) const in Client.cpp.o
boost::system::error_category::std_category::equivalent(std::__1::error_code const&, int) const in Client.cpp.o
boost::thread_exception::thread_exception(int, char const*) in Client.cpp.o
___cxx_global_var_init in Client.cpp.o
___cxx_global_var_init.1 in Client.cpp.o
boost::system::error_category::std_category::equivalent(int, std::__1::error_condition const&) const in main.cpp.o
boost::system::error_category::std_category::equivalent(std::__1::error_code const&, int) const in main.cpp.o
... "boost::thread::join_noexcept()", referenced from:
boost::thread::join() in NetworkManager.cpp.o "boost::thread::native_handle()", referenced from:
boost::thread::get_id() const in NetworkManager.cpp.o "boost::thread::hardware_concurrency()", referenced from:
_main in main.cpp.o "boost::thread::start_thread_noexcept()", referenced from:
boost::thread::start_thread() in NetworkManager.cpp.o "boost::thread::detach()", referenced from:
boost::thread::~thread() in NetworkManager.cpp.o "boost::thread::joinable() const", referenced from:
boost::thread_group::join_all() in NetworkManager.cpp.o "typeinfo for boost::detail::thread_data_base", referenced from:
typeinfo for boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf1<void, NetworkManager, boost::shared_ptr<boost::asio::io_service> >, boost::_bi::list2<boost::_bi::value<NetworkManager*>, boost::_bi::value<boost::shared_ptr<boost::asio::io_service> > > > > in NetworkManager.cpp.o "vtable for boost::detail::thread_data_base", referenced from:
boost::detail::thread_data_base::thread_data_base() in NetworkManager.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[3]: *** [AuthServer] Error 1 make[2]: *** [CMakeFiles/AuthServer.dir/all] Error 2 make[1]:
*** [CMakeFiles/AuthServer.dir/rule] Error 2 make: *** [AuthServer] Error 2
I've been working on windows only with C++ until now and so I might have made so giant mistake with the Cmake file but I don't know what.
The libs I look for are found and everything seems to work. I know the libs are the right ones since on the windows version, they are the one I use.
Down the line I want to make one makefile for windows and unix so I can stop working with the SLN.
I needed to use
find_package
for boost (FindBoost) or
find_library
for EACH file.
Related
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.
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.
I am trying to use boost in my c++ project in macOS Sierra. I've installed boost using home-brew, like so:
brew install boost
My CMakeLists.txt file looks like
cmake_minimum_required(VERSION 3.8)
project(sr)
set(CMAKE_CXX_STANDARD 14)
set(Boost_USE_STATIC_LIBS OFF) # only find static libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.64.0 COMPONENTS system log log_setup thread date_time filesystem regex chrono atomic REQUIRED)
include_directories(src)
include_directories(lib/easylogging++)
include_directories(${Boost_INCLUDE_DIRS})
add_subdirectory(src)
add_subdirectory(sr_tests)
set(SOURCE_FILES main.cpp lib/easylogging++/easylogging++.cc)
add_executable(sr_out ${SOURCE_FILES})
target_link_libraries(sr_out ${Boost_LIBRARIES} sr)
My main.cpp is simply
#include
int main() {
BOOST_LOG_TRIVIAL(info) << "hi";
return 1;
}
In the build phase, the binary fails to link with
➜ build git:(master) ✗ cmake ..
-- The C compiler identification is AppleClang 8.1.0.8020042
-- The CXX compiler identification is AppleClang 8.1.0.8020042
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Boost version: 1.64.0
-- Found the following Boost libraries:
-- system
-- log
-- log_setup
-- thread
-- date_time
-- filesystem
-- regex
-- chrono
-- atomic
-- Configuring done
-- Generating done
-- Build files have been written to: /Volumes/sr/sr/build
➜ build git:(master) ✗ make VERBOSE=1
/usr/local/Cellar/cmake/3.8.2/bin/cmake -H/Volumes/sr/sr -B/Volumes/sr/sr/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.8.2/bin/cmake -E cmake_progress_start /Volumes/sr/sr/build/CMakeFiles /Volumes/sr/sr/build/CMakeFiles/progress.marks
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/Makefile2 all
/Library/Developer/CommandLineTools/usr/bin/make -f src/CMakeFiles/sr.dir/build.make src/CMakeFiles/sr.dir/depend
cd /Volumes/sr/sr/build && /usr/local/Cellar/cmake/3.8.2/bin/cmake -E cmake_depends "Unix Makefiles" /Volumes/sr/sr /Volumes/sr/sr/src /Volumes/sr/sr/build /Volumes/sr/sr/build/src /Volumes/sr/sr/build/src/CMakeFiles/sr.dir/DependInfo.cmake --color=
/Library/Developer/CommandLineTools/usr/bin/make -f src/CMakeFiles/sr.dir/build.make src/CMakeFiles/sr.dir/build
make[2]: Nothing to be done for `src/CMakeFiles/sr.dir/build'.
[ 30%] Built target sr
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/sr_out.dir/build.make CMakeFiles/sr_out.dir/depend
cd /Volumes/sr/sr/build && /usr/local/Cellar/cmake/3.8.2/bin/cmake -E cmake_depends "Unix Makefiles" /Volumes/sr/sr /Volumes/sr/sr /Volumes/sr/sr/build /Volumes/sr/sr/build /Volumes/sr/sr/build/CMakeFiles/sr_out.dir/DependInfo.cmake --color=
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/sr_out.dir/build.make CMakeFiles/sr_out.dir/build
[ 40%] Linking CXX executable sr_out
/usr/local/Cellar/cmake/3.8.2/bin/cmake -E cmake_link_script CMakeFiles/sr_out.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/sr_out.dir/main.cpp.o CMakeFiles/sr_out.dir/lib/easylogging++/easylogging++.cc.o -o sr_out /usr/local/lib/libboost_system-mt.dylib /usr/local/lib/libboost_log-mt.dylib /usr/local/lib/libboost_log_setup-mt.dylib /usr/local/lib/libboost_thread-mt.dylib /usr/local/lib/libboost_date_time-mt.dylib /usr/local/lib/libboost_filesystem-mt.dylib /usr/local/lib/libboost_regex-mt.dylib /usr/local/lib/libboost_chrono-mt.dylib /usr/local/lib/libboost_atomic-mt.dylib src/libsr.a
Undefined symbols for architecture x86_64:
"boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*)", referenced from:
boost::log::v2s_mt_posix::record::reset() in main.cpp.o
"boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)", referenced from:
boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::auto_release::~auto_release() in main.cpp.o
"boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&)", referenced from:
boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::record_pump(boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>&, boost::log::v2s_mt_posix::record&) in main.cpp.o
"boost::log::v2s_mt_posix::aux::unhandled_exception_count()", referenced from:
boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::record_pump(boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>&, boost::log::v2s_mt_posix::record&) in main.cpp.o
boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::~record_pump() in main.cpp.o
"boost::log::v2s_mt_posix::core::open_record(boost::log::v2s_mt_posix::attribute_set const&)", referenced from:
boost::log::v2s_mt_posix::record boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex> >::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, boost::log::v2s_mt_posix::trivial::severity_level const> >(boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, boost::log::v2s_mt_posix::trivial::severity_level const> const&) in main.cpp.o
"boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)", referenced from:
boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex> >::push_record_unlocked(boost::log::v2s_mt_posix::record&&) in main.cpp.o
"boost::log::v2s_mt_posix::sources::aux::get_severity_level()", referenced from:
boost::log::v2s_mt_posix::sources::aux::severity_level<boost::log::v2s_mt_posix::trivial::severity_level>::set_value(boost::log::v2s_mt_posix::trivial::severity_level) in main.cpp.o
"boost::log::v2s_mt_posix::trivial::logger::get()", referenced from:
_main in main.cpp.o
"boost::log::v2s_mt_posix::core::get_logging_enabled() const", referenced from:
boost::log::v2s_mt_posix::record boost::log::v2s_mt_posix::sources::basic_composite_logger<char, boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex>, boost::log::v2s_mt_posix::sources::features<boost::log::v2s_mt_posix::sources::severity<boost::log::v2s_mt_posix::trivial::severity_level> > >::open_record<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, boost::log::v2s_mt_posix::trivial::severity_level const> >(boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, boost::log::v2s_mt_posix::trivial::severity_level const> 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[2]: *** [sr_out] Error 1
make[1]: *** [CMakeFiles/sr_out.dir/all] Error 2
make: *** [all] Error 2
➜ build git:(master) ✗
I would really appreciate any help in getting this up and running.
The problem was that the Boost Logging library had to be dynamically linked. I fixed my CMakeLists.txt file to add this line:
add_definitions(-DBOOST_LOG_DYN_LINK=1)
This fixed the issue
This is a problem I've been having for over a year that I continue to return to every so often, and it's the main reason I have always been scared away from using theos(for building iOS tweaks). Today I have decided to try again, and I have made a test theos project once more and attempted to build it with 'make'. This is the sample code I'm attempting to build:
#include <string>
#include <cstdio>
struct Mine
{
std::string nice;
Mine(std::string p)
{
nice = p;
}
virtual void poop()
{
printf("%s", this->nice.c_str());
}
};
int main()
{
Mine* mine = new Mine("nice");
mine->poop();
return 0;
}
This is the basic Makefile I'm using to build this in theos:
GO_EASY_ON_ME=1
messages=yes
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = tweak_test
tweak_test_CXXFLAGS = -stdlib=libc++ -std=c++11
tweak_test_LDFLAGS = -stdlib=libc++ -std=c++11
tweak_test_FILES = main.cpp
include $(THEOS_MAKE_PATH)/tweak.mk
Notice that I am in fact specifying that I would like to use the libc++ STL when building (I must use libc++ for the tweak I am building since the app that I am hooking uses it, and there would be runtime conflicts if they were different, namely due to libc++'s short string optimization feature, which makes its strings use up 24 bytes rather than 8 on libstdc++, among other things).
No matter what I do, however, I always get linker errors with std::string related functions. This is the output from theos, with verbose turned on so that execution is printed:
Ryans-MacBook-Air:tweak_test ryan$ make
> Making all for tweak tweak_test…
set -o pipefail; (/Applications/Xcode.app/Contents/Developer/usr/bin/make -f Makefile --no-print-directory --no-keep-going \
internal-library-compile \
_THEOS_CURRENT_TYPE=tweak THEOS_CURRENT_INSTANCE=tweak_test _THEOS_CURRENT_OPERATION=compile \
THEOS_BUILD_DIR="." _THEOS_MAKE_PARALLEL=yes)
set -o pipefail; (mkdir -p /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/)
(printf "\e[0;3%im==> \e[1;39m%s…\e[m\n" 2 "Compiling main.cpp (armv7)"); set -o pipefail; (xcrun -sdk iphoneos clang++ -x c++ -c -I/opt/theos/include -include /opt/theos/Prefix.pch -DTARGET_IPHONE=1 -O0 -Wall -isysroot "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk" -D__IPHONE_OS_VERSION_MIN_REQUIRED=__IPHONE_6_0 -miphoneos-version-min=6.0 -fmodules -fcxx-modules -fmodule-name=tweak_test -fbuild-session-file=/Users/ryan/tweaks/tweak_test/.theos/build_session -fmodules-prune-after=345600 -fmodules-prune-interval=86400 -fmodules-validate-once-per-build-session -I/opt/theos/vendor/include -I/opt/theos/include/_fallback -DDEBUG -ggdb -O0 -DTHEOS_INSTANCE_NAME="\"tweak_test\"" -arch armv7 main.cpp -o /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/main.cpp.262db704.o)
==> Compiling main.cpp (armv7)…
set -o pipefail; (mkdir -p /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7)
(printf "\e[0;3%im==> \e[1;39m%s…\e[m\n" 3 "Linking tweak tweak_test (armv7)"); set -o pipefail; (xcrun -sdk iphoneos clang++ -L/opt/theos/lib -L/opt/theos/vendor/lib -F/opt/theos/vendor/lib -framework CydiaSubstrate -dynamiclib -install_name "/Library/MobileSubstrate/DynamicLibraries/tweak_test.dylib" -isysroot "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.1.sdk" -D__IPHONE_OS_VERSION_MIN_REQUIRED=__IPHONE_6_0 -miphoneos-version-min=6.0 -Wl,-segalign,4000 -multiply_defined suppress -arch armv7 -stdlib=libc++ -std=c++11 -ggdb -O0 -o "/Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/tweak_test.dylib" /Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/main.cpp.262db704.o | (grep -v 'usr/lib/dylib1.o, missing required architecture' || true))
==> Linking tweak tweak_test (armv7)…
Undefined symbols for architecture armv7:
"std::string::c_str() const", referenced from:
Mine::poop() in main.cpp.262db704.o
"std::allocator<char>::allocator()", referenced from:
_main in main.cpp.262db704.o
"std::allocator<char>::~allocator()", referenced from:
_main in main.cpp.262db704.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
_main in main.cpp.262db704.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()", referenced from:
Mine::Mine(std::string) in main.cpp.262db704.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
_main in main.cpp.262db704.o
Mine::Mine(std::string) in main.cpp.262db704.o
"std::string::operator=(std::string const&)", referenced from:
Mine::Mine(std::string) in main.cpp.262db704.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [/Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/tweak_test.dylib] Error 1
make[2]: *** [/Users/ryan/tweaks/tweak_test/.theos/obj/debug/armv7/tweak_test.dylib] Error 2
make[1]: *** [internal-library-all_] Error 2
make: *** [tweak_test.all.tweak.variables] Error 2
Note that when building with libstdc++ this builds correctly. I believe that the problem is with either being linked with clang rather than clang++ (doesn't appear to be), or that it is being linked with a different STL than what it had been compiled with (also does not appear to be the case, based on the above verbose output).
If someone could help me with this it would be a year-and-a-half old problem finally put to rest.
Thanks in advance!
I'm working on compiling a SCIP dynamic library. SCIP is implemented in C, and our optimization project is all Java, so we're wanting to use JNA to access it. We've written a C++ wrapper to build the dynamic library, and I'm having issues compiling it on my Mac (running Yosemite 10.10.2). Here's my version of gcc and g++:
> gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
> g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
We're using CMake (version 3.2.1) to build the project. Here's our main CMakeLists.txt:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -O2 -Wall -DNDEBUG")
if(CMAKE_COMPILER_IS_GNUCXX)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC" )
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC" )
endif()
endif()
if(APPLE)
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0")
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_OSX_ARCHITECTURES "x86_64")
endif()
if(WIN32)
add_definitions(-DUNICODE -D_UNICODE)
set(TARGET_ARCHITECTURE "x86")
endif()
set(LIB_TYPE SHARED)
include_directories("/path/to/scipoptsuite-3.1.1/scip-3.1.1/src")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
add_library(scipLibrary ${LIB_TYPE} "stdafx.cpp")
Here's the output of make VERBOSE=1:
/usr/local/Cellar/cmake/3.2.1/bin/cmake -H/path/to/scip -B/path/to/scip/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.2.1/bin/cmake -E cmake_progress_start /path/to/scip/build/CMakeFiles /path/to/scip/build/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f source/CMakeFiles/scipLibrary.dir/build.make source/CMakeFiles/scipLibrary.dir/depend
cd /path/to/scip/build && /usr/local/Cellar/cmake/3.2.1/bin/cmake -E cmake_depends "Unix Makefiles" /path/to/scip /path/to/scip/source /path/to/scip/build /path/to/scip/build/source /path/to/scip/build/source/CMakeFiles/scipLibrary.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f source/CMakeFiles/scipLibrary.dir/build.make source/CMakeFiles/scipLibrary.dir/build
/usr/local/Cellar/cmake/3.2.1/bin/cmake -E cmake_progress_report /path/to/scip/build/CMakeFiles 1
[100%] Building CXX object source/CMakeFiles/scipLibrary.dir/stdafx.cpp.o
cd /path/to/scip/build/source && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DscipLibrary_EXPORTS -std=c++0x -O2 -Wall -DNDEBUG -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -fPIC -I/path/to/scipoptsuite-3.1.1/scip-3.1.1/src -I/path/to/scip/source -o CMakeFiles/scipLibrary.dir/stdafx.cpp.o -c /path/to/scip/source/stdafx.cpp
Linking CXX shared library ../output/libscipLibrary.dylib
cd /path/to/scip/build/source && /usr/local/Cellar/cmake/3.2.1/bin/cmake -E cmake_link_script CMakeFiles/scipLibrary.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++0x -O2 -Wall -DNDEBUG -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -dynamiclib -Wl,-headerpad_max_install_names -o ../output/libscipLibrary.dylib -install_name #rpath/libscipLibrary.dylib CMakeFiles/scipLibrary.dir/stdafx.cpp.o
Undefined symbols for architecture x86_64:
"_SCIPaddBilinTermQuadratic", referenced from:
_LibSCIPaddBilinTermQuadratic in stdafx.cpp.o
"_SCIPaddCoefLinear", referenced from:
_LibSCIPaddCoefLinear in stdafx.cpp.o
"_SCIPaddCons", referenced from:
_LibSCIPaddCons in stdafx.cpp.o
"_SCIPaddQuadVarLinearCoefQuadratic", referenced from:
_LibSCIPaddQuadVarLinearCoefQuadratic in stdafx.cpp.o
"_SCIPaddSquareCoefQuadratic", referenced from:
_LibSCIPaddSquareCoefQuadratic in stdafx.cpp.o
"_SCIPaddVar", referenced from:
_LibSCIPaddVar in stdafx.cpp.o
"_SCIPblkmem", referenced from:
_LibSCIPexprCreateLinear in stdafx.cpp.o
_LibSCIPexprCreate in stdafx.cpp.o
_LibSCIPexprCreateMonomial in stdafx.cpp.o
_LibSCIPexprCreatePolynomial in stdafx.cpp.o
_LibSCIPexprtreeCreate in stdafx.cpp.o
"_SCIPchgVarLb", referenced from:
_LibSCIPchgVarLb in stdafx.cpp.o
"_SCIPchgVarObj", referenced from:
_LibSCIPchgVarObj in stdafx.cpp.o
"_SCIPchgVarUb", referenced from:
_LibSCIPchgVarUb in stdafx.cpp.o
"_SCIPcreate", referenced from:
_LibSCIPcreate in stdafx.cpp.o
"_SCIPcreateConsBasicAbspower", referenced from:
_LibSCIPcreateConsBasicAbspower in stdafx.cpp.o
"_SCIPcreateConsBasicLinear", referenced from:
_LibSCIPcreateConsBasicLinear in stdafx.cpp.o
"_SCIPcreateConsBasicNonlinear", referenced from:
_LibSCIPcreateConsBasicNonlinear in stdafx.cpp.o
"_SCIPcreateConsBasicQuadratic", referenced from:
_LibSCIPcreateConsBasicQuadratic in stdafx.cpp.o
"_SCIPcreateConsBasicSetpart", referenced from:
_LibSCIPcreateConsBasicSetpart in stdafx.cpp.o
"_SCIPcreateProbBasic", referenced from:
_LibSCIPcreateProbBasic in stdafx.cpp.o
"_SCIPcreateVarBasic", referenced from:
_LibSCIPcreateVarBasic in stdafx.cpp.o
"_SCIPexprCreate", referenced from:
_LibSCIPexprCreate in stdafx.cpp.o
"_SCIPexprCreateLinear", referenced from:
_LibSCIPexprCreateLinear in stdafx.cpp.o
"_SCIPexprCreateMonomial", referenced from:
_LibSCIPexprCreateMonomial in stdafx.cpp.o
"_SCIPexprCreatePolynomial", referenced from:
_LibSCIPexprCreatePolynomial in stdafx.cpp.o
"_SCIPexprtreeCreate", referenced from:
_LibSCIPexprtreeCreate in stdafx.cpp.o
"_SCIPexprtreeFree", referenced from:
_LibSCIPexprtreeFree in stdafx.cpp.o
"_SCIPexprtreeSetVars", referenced from:
_LibSCIPexprtreeSetVars in stdafx.cpp.o
"_SCIPfree", referenced from:
_LibSCIPfree in stdafx.cpp.o
"_SCIPfreeTransform", referenced from:
_LibSCIPfreeTransform in stdafx.cpp.o
"_SCIPgetBestSol", referenced from:
_LibSCIPprintSolution in stdafx.cpp.o
_LibSCIPgetBestSol in stdafx.cpp.o
"_SCIPgetNSols", referenced from:
_LibSCIPgetNSols in stdafx.cpp.o
"_SCIPgetStatus", referenced from:
_LibSCIPgetStatus in stdafx.cpp.o
"_SCIPincludeDefaultPlugins", referenced from:
_LibSCIPincludeDefaultPlugins in stdafx.cpp.o
"_SCIPmajorVersion", referenced from:
_LibSCIPmajorVersion in stdafx.cpp.o
"_SCIPmessagePrintError", referenced from:
_LibSCIPincludeDefaultPlugins in stdafx.cpp.o
_LibSCIPcreateProbBasic in stdafx.cpp.o
_LibSCIPchgVarLb in stdafx.cpp.o
_LibSCIPchgVarUb in stdafx.cpp.o
_LibSCIPaddVar in stdafx.cpp.o
_LibSCIPexprtreeSetVars in stdafx.cpp.o
_LibSCIPexprtreeFree in stdafx.cpp.o
...
"_SCIPmessagePrintErrorHeader", referenced from:
_LibSCIPincludeDefaultPlugins in stdafx.cpp.o
_LibSCIPcreateProbBasic in stdafx.cpp.o
_LibSCIPchgVarLb in stdafx.cpp.o
_LibSCIPchgVarUb in stdafx.cpp.o
_LibSCIPaddVar in stdafx.cpp.o
_LibSCIPexprtreeSetVars in stdafx.cpp.o
_LibSCIPexprtreeFree in stdafx.cpp.o
...
"_SCIPminorVersion", referenced from:
_LibSCIPminorVersion in stdafx.cpp.o
"_SCIPpresolve", referenced from:
_LibSCIPpresolve in stdafx.cpp.o
"_SCIPprintOrigProblem", referenced from:
_LibSCIPprintProblemCIP in stdafx.cpp.o
_LibSCIPprintProblemMPS in stdafx.cpp.o
_LibSCIPprintProblemLP in stdafx.cpp.o
_LibSCIPprintProblemCIPToFile in stdafx.cpp.o
_LibSCIPprintProblemMPSToFile in stdafx.cpp.o
_LibSCIPprintProblemLPToFile in stdafx.cpp.o
"_SCIPprintSol", referenced from:
_LibSCIPprintSolution in stdafx.cpp.o
"_SCIPreleaseCons", referenced from:
_LibSCIPreleaseCons in stdafx.cpp.o
"_SCIPreleaseVar", referenced from:
_LibSCIPreleaseVar in stdafx.cpp.o
"_SCIPsetObjsense", referenced from:
_LibSCIPsetObjsense in stdafx.cpp.o
"_SCIPsolve", referenced from:
_LibSCIPsolve in stdafx.cpp.o
"_SCIPsubversion", referenced from:
_LibSCIPsubversion in stdafx.cpp.o
"_SCIPtechVersion", referenced from:
_LibSCIPtechVersion in stdafx.cpp.o
"_SCIPvarGetLPSol_rec", referenced from:
solGetArrayVal(SCIP_Sol*, SCIP_Var*) in stdafx.cpp.o
"_SCIPvarGetNLPSol_rec", referenced from:
solGetArrayVal(SCIP_Sol*, SCIP_Var*) in stdafx.cpp.o
"_SCIPvarGetOrigvarSum", referenced from:
_LibSCIPsolGetVal in stdafx.cpp.o
"_SCIPvarGetPseudoSol", referenced from:
solGetArrayVal(SCIP_Sol*, SCIP_Var*) in stdafx.cpp.o
"_SCIPversion", referenced from:
_LibSCIPversion in stdafx.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]: *** [output/libscipLibrary.dylib] Error 1
make[1]: *** [source/CMakeFiles/scipLibrary.dir/all] Error 2
make: *** [all] Error 2
You can see that the problem is that the linker is giving us an ld: symbol(s) not found for architecture x86_64 error. I've searched a lot to try and figure out how to solve this, but I haven't had any luck.
I'm not sure it's necessary to provide the contents of stdafx.h or stdafx.cpp, so I'll leave them out for now, but if it's necessary, let me know, and I can provide them.
Ok, I had made a mistake where I didn't build scipoptlib, so there was no library to build against (sorry, I've never created a dynamic library before). Running make scipoptlib IPOPT=true SHARED=true in /path/to/scipoptsuite-3.1.1 was all that was needed to do that.
Here's the updated CMakeLists.txt that references the single shared scipoptlib:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -O2 -Wall -DNDEBUG")
if(CMAKE_COMPILER_IS_GNUCXX)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
endif()
endif()
if(APPLE)
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0")
set(CMAKE_MACOSX_RPATH 1)
endif()
if(WIN32)
add_definitions(-DUNICODE -D_UNICODE)
set(TARGET_ARCHITECTURE "x86")
endif()
include_directories("/path/to/scipoptsuite-3.1.1/scip-3.1.1/src/")
add_library(scipLibrary SHARED "stdafx.cpp")
target_link_libraries(scipLibrary "/path/to/scipoptsuite-3.1.1/lib/libscipopt-3.1.1.darwin.x86_64.gnu.opt.so")
I can actually generate the dylib now, which is great! However, now JNA is throwing up (saying it can't find the dylib), but that's probably the topic of another SO thread.