OSX 10.11.3 (El Capitan)
I'm getting link errors while building the first example from the Boost::Log tutorial.
#include <boost/log/trivial.hpp>
int main(int, char*[])
{
BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
BOOST_LOG_TRIVIAL(info) << "An informational severity message";
BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
BOOST_LOG_TRIVIAL(error) << "An error severity message";
BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
return 0;
}
Here are the diagnostics:
$ c++ trivial_log_test.cpp
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 trivial_log_test-6968b8.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 trivial_log_test-6968b8.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 trivial_log_test-6968b8.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 trivial_log_test-6968b8.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 trivial_log_test-6968b8.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 trivial_log_test-6968b8.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::rv<boost::log::v2s_mt_posix::record>&) in trivial_log_test-6968b8.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 trivial_log_test-6968b8.o
"boost::log::v2s_mt_posix::trivial::logger::get()", referenced from:
_main in trivial_log_test-6968b8.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>, void, void, void, void, void, void, void, void, void> >::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 trivial_log_test-6968b8.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Several similar questions said that the following gave useful information:
$ clang++ -E -x c++ - -v < /dev/null
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -disable-free -disable-llvm-verifier -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 253.9 -v -dwarf-column-info -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/chap/private/cpp/BOOST_TESTING/log_test -ferror-limit 19 -fmessage-length 176 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ -
clang -cc1 version 7.0.2 based upon LLVM 3.7.0svn default target x86_64-apple-darwin15.3.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 332 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
Homebrew is installed and up-to-date. I reinstalled Boost:
$ brew reinstall boost
==> Reinstalling boost
==> Downloading https://homebrew.bintray.com/bottles/boost-1.60.0_1.el_capitan.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/boost-1.60.0_1.el_capitan.bottle.tar.gz
==> Pouring boost-1.60.0_1.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/boost/1.60.0_1: 11,139 files, 436.0M
In other similar questions about link errors using the Boost libraries, a common solution was to run bootstrap.sh to build the b2 executable to compile some libraries. However, these people installed Boost without using Homebrew. Homebrew's installation of Boost looks different than the directory structure that's described by the Boost 'getting started' page - notably in that it doesn't contain either the bootstrap.sh script or the b2 binary. This makes me think that brew install boost has taken care of it.
Can someone suggest a next step?
UPDATE 1: Corrected statement about bootstrap.sh and b2.
The solution, provided by someone on the Homebrew mailing list, was to compile my program using the following flags:
c++ -DBOOST_LOG_DYN_LINK -lboost_log-mt trivial_log_test.cpp
Since I got the Boost "bottle", I got prebuilt versions of the binary libraries. No need for bootstrap.sh / b2.
Related
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.
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 upgraded to maverics and now the macports version of boost-python doesn't work.
I installed ports: gcc48 and boost +python33.
I tried to compile this program with c++11 or without c++11:
#include <boost/python.hpp>
class A {};
BOOST_PYTHON_MODULE(libblah) {
boost::python::class_<A>("A");
}
I used cmake, but the build commands generated are below along with the linker error that I get:
[100%] Building CXX object CMakeFiles/a.dir/a.cc.o
g++ -Da_EXPORTS -std=gnu++0x -save-temps=obj -arch x86_64 -fPIC -I/Users/neil/nn/src -I/opt/local/include -I/opt/local/include/freetype2 -I/opt/local/Library/Frameworks/Python.framework/Headers -F/usr/local/Qt-5.2.0/lib -I/usr/local/Qt-5.2.0/lib/QtCore.framework/Headers -I/usr/local/Qt-5.2.0/mkspecs/macx-clang -I/usr/local/Qt-5.2.0/lib/QtGui.framework/Headers -I/System/Library/Frameworks/OpenGL.framework/Headers -I/usr/local/Qt-5.2.0/lib/QtOpenGL.framework/Headers -I/usr/local/Qt-5.2.0/lib/QtWidgets.framework/Headers -I/opt/local/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m -I/Users/neil/nn/src/. -o CMakeFiles/a.dir/a.cc.o -c /Users/neil/nn/src/a.cc
Linking CXX shared module liba.so
g++ -std=gnu++0x -save-temps=obj -arch x86_64 -bundle -Wl,-headerpad_max_install_names -o liba.so CMakeFiles/a.dir/a.cc.o -L/opt/local/lib -L/Users/neil/nn/src /opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/libpython3.3.dylib /opt/local/lib/libboost_python-mt.dylib -Wl,-rpath,/opt/local/lib -Wl,-rpath,/Users/neil/nn/src
Undefined symbols for architecture x86_64:
"boost::python::objects::function_object(boost::python::objects::py_function const&, std::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&)", referenced from:
boost::python::api::object boost::python::detail::make_function_aux<void (*)(_object*), boost::python::default_call_policies, boost::mpl::vector2<void, _object*>, mpl_::int_<0> >(void (*)(_object*), boost::python::default_call_policies const&, boost::mpl::vector2<void, _object*> const&, std::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&, mpl_::int_<0>) in a.cc.o
"boost::python::objects::register_dynamic_id_aux(boost::python::type_info, std::pair<void*, boost::python::type_info> (*)(void*))", referenced from:
void boost::python::objects::register_dynamic_id<A>(A*) in a.cc.o
ld: symbol(s) not found for architecture x86_64
How can I work around this bug without installing boost by myself. As with this Related question, the symbols in the library
nm libboost_python-mt.dylib | c++filt | grep boost::python::objects::function_object
are found:
0000000000013d60 T boost::python::objects::function_object(boost::python::objects::py_function const&)
0000000000013d00 T boost::python::objects::function_object(boost::python::objects::py_function const&, std::__1::pair<boost::python::detail::keyword const*, boost::python::detail::keyword const*> const&)
However, they have std::__1 prefixes, which do not match what is expected in the undefined symbols errors.
I changed the compiler to clang++, and that worked. Would have preferred a better solution.
I'm following this:
http://sadeepj.blogspot.com.br/2012/03/installing-and-configuring-opencv-to.html
I had a problem, compiling. But I already fixed it, modifying 2 files...
Now I'm trying to run that example.
And I get this error message:
Ld
/Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Products/Debug/DemoOpenCV2
normal x86_64
cd /Users/eduardoreis/Documents/XCodeDevelopment/DemoOpenCV2
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
-L/Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Products/Debug
-F/Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Products/Debug
-filelist /Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Intermediates/DemoOpenCV2.build/Debug/DemoOpenCV2.build/Objects-normal/x86_64/DemoOpenCV2.LinkFileList
-mmacosx-version-min=10.8 -stdlib=libc++ -lopencv_core.2.4.6 -lopencv_highgui.2.4.6 -Xlinker -dependency_info -Xlinker /Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Intermediates/DemoOpenCV2.build/Debug/DemoOpenCV2.build/Objects-normal/x86_64/DemoOpenCV2_dependency_info.dat
-o /Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Products/Debug/DemoOpenCV2
ld: library not found for -lopencv_core.2.4.6 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
I follows all steps already. And I can't even build it.
Please, help me.
[Before someone says that it is a duplicated post, I know it, here is the original one:
C++ linker errors with OpenCV.
I'm sorry. But I can't even comment on that one :/ ]
Wow, Finally solved:
Some considerations:
Realize that even it is looking for -l opencv_core.2.4.6, the
compiler will get the right file, if it is added correctly with other
name, in this case libopencv_core.2.4.dylib
I was adding the files with Project>Add files to... and then creating a group and dragging the files into the group. This was messing up the linkings in Project>Link Binary with Libraries. So I had to do it again by dragging the files in the group into that spot.
After theses things I had the situation where I had the two files (core and highgui) and 4 errors:
Ld
/Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Products/Debug/DemoOpenCV2
normal x86_64
cd /Users/eduardoreis/Documents/XCodeDevelopment/DemoOpenCV2
setenv MACOSX_DEPLOYMENT_TARGET 10.8
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
-L/Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Products/Debug
-L/Users/eduardoreis/Downloads/opencv-2.4.6.1/build/lib/Debug -L/usr/local/lib/python2.7/site-packages -L/usr/local/lib/python2.7/site-packages/PyQt4 -L/usr/local/lib/wine -L/usr/local/Cellar/wine/1.4.1/lib -L/usr/local/Cellar/qt/4.8.5/lib -L/usr/local/Cellar/qscintilla2/2.7.1/lib -L/usr/local/Cellar/libicns/0.8.1/lib -L/usr/local/Cellar/jasper/1.900.1/lib -L/usr/local/Cellar/jpeg/8d/lib -L/usr/local/Cellar/little-cms/1.19/lib -L/usr/local/Cellar/libpng/1.5.14/lib -L/usr/local/Cellar/libtiff/4.0.3/lib -F/Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Products/Debug
-F/usr/local/lib -filelist /Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Intermediates/DemoOpenCV2.build/Debug/DemoOpenCV2.build/Objects-normal/x86_64/DemoOpenCV2.LinkFileList
-mmacosx-version-min=10.8 -stdlib=libc++ -lopencv_core.2.4 -lopencv_highgui.2.4 -Xlinker -dependency_info -Xlinker /Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Intermediates/DemoOpenCV2.build/Debug/DemoOpenCV2.build/Objects-normal/x86_64/DemoOpenCV2_dependency_info.dat
-o /Users/eduardoreis/Library/Developer/Xcode/DerivedData/DemoOpenCV2-cqudsdzwopsadacnkbwrsxuncofg/Build/Products/Debug/DemoOpenCV2
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__1::basic_string, std::__1::allocator > const&,
int)", referenced from:
_main in main.o "cv::imread(std::__1::basic_string, std::__1::allocator > const&,
int)", referenced from:
_main in main.o "cv::imshow(std::__1::basic_string, std::__1::allocator > const&,
cv::_InputArray const&)", referenced from:
_main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Then (thanks God and some days of googling) I got this:
Select your project, go to the Build Settings tab, filter by c++
standard library, and set this parameter to libstdc++ (GNU C++
standard library).
from: Undefined symbols for architecture x86_64 error when linking OpenCV in Xcode
And finally it was sunny again in my code environment...
I decided to go and give Clang a go, since I've heard good things about it, and I wanted to try out some of the C++11 features. So, as usual I started out with a simple hello world program.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world" << endl;
return 0;
}
What compiled just fine using GCC isn't compiling in Clang. Instead, I get this error.
Apple clang version 4.1 (tags/Apple/clang-421.11.65) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 134.9 -v -resource-dir /usr/bin/../lib/clang/4.1 -fmodule-cache-path /var/folders/js/j_8fpm_j0vl1d_2r_lsxlddm0000gn/T/clang-module-cache -fdeprecated-macro -fdebug-compilation-dir /Users/alexanderstein/Desktop/build -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/js/j_8fpm_j0vl1d_2r_lsxlddm0000gn/T/test-4P1Ij1.o -x c++ /Users/alexanderstein/Desktop/Programming/Sandbox/C_C++/test.cpp
clang -cc1 version 4.1 based upon LLVM 3.1svn default target x86_64-apple-darwin12.2.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/usr/bin/../lib/clang/4.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o a.out /var/folders/js/j_8fpm_j0vl1d_2r_lsxlddm0000gn/T/test-4P1Ij1.o -lSystem /usr/bin/../lib/clang/4.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from:
_main in test-4P1Ij1.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in test-4P1Ij1.o
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in test-4P1Ij1.o
"std::cout", referenced from:
_main in test-4P1Ij1.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in test-4P1Ij1.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in test-4P1Ij1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
As per requested in the comments:
You need to use clang++, as clang is the C compiler.