I'm trying to create a project that uses the Boost library. I'm on OS X 10.9.5 (I should update that) and using Xcode 6.2. I installed boost with homebrew brew install boost and it's located in /usr/local/Cellar/boost/1.59.0. I added the path the the /usr/local/Cellar/boost/1.59.0/include to the header search path in Xcode and it seems to recognize it because the autocomplete hinting works.
In the boost documentation it mentions that some of the Boost libraries must be built before they can be used. I assume homebrew took care of that because I have a bunch of .a and .dylib files in /usr/local/Cellar/boost/1.59.0/lib
I'm still new to C++ and the Xcode build process but it seems I still need to link the compiled libraries to my project. I tried adding the path /usr/local/Cellar/boost/1.59.0/lib to my project's library search paths but I'm not sure if that is correct.
Here is the error I get when I try to build my project.
Undefined symbols for architecture x86_64:
"boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::create_directory(boost::filesystem::path const&) in main.o
"boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::exists(boost::filesystem::path const&) in main.o
"boost::system::system_category()", referenced from:
___cxx_global_var_init2 in main.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in main.o
___cxx_global_var_init1 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)
Is there something else I need to configure to get this to work?
Adding the path is correct but you also need to specify the libraries you need. On the commandline you would use -l for that in Xcode you can add them to Other Linker Flags.
The libraries you need are boost_filesystem and boost_system.
Related
I am writing a test for a Biquad Filter class I have written in C++, and I am attempting to use to FFTWPP header to simplify the use of the FFTW library. I have successfully built and run the FFTWPP examples, so I can be sure that the FFTW3 library is successfully built and installed on my Mac (running OS Catalina 10.15.5 (19F101)).
I have managed to include the FFTW lib directory into the cmake project definitions, and I have added the appropriate include paths into the CMAKE file:
cmake_minimum_required(VERSION 3.16)
project(IIR)
set(CMAKE_CXX_STANDARD 14)
find_package(Python 3.7 COMPONENTS Development) # Used for MatplotlibPP
include_directories(.)
include_directories(./../../../fftwpp/)
include_directories(./../../../fftw-3.3.8/api/)
include_directories(./../../../matplotlib-cpp/) #Plotting
include_directories(./../../../AudioFile/) #AudiofileIO
include_directories(/usr/local/include) # contains includes for FFTW3
link_directories(.)
link_directories(/usr/local/lib)# contains binary for FFTW3
find_library(
fftw3
NAMES fftw lfftw3 libfftw3
HINTS /usr/local/lib
)
add_executable(IIR
Test_BiquadFilter.cpp)
target_link_libraries(IIR PUBLIC Python fftw3)
However, it appears the linker is failing to link the symbols through the FFTWPP header:
[100%] Linking CXX executable IIR
Undefined symbols for architecture x86_64:
"fftwpp::ThreadBase::ThreadBase()", referenced from:
fftwpp::fftw::fftw(unsigned int, int, unsigned int, unsigned int) in Test_BiquadFilter.cpp.o
"fftwpp::fftw::maxthreads", referenced from:
_main in Test_BiquadFilter.cpp.o
fftwpp::fftw::Setup(std::__1::complex<double>*, std::__1::complex<double>*) in Test_BiquadFilter.cpp.o
"fftwpp::fftw::testseconds", referenced from:
fftwpp::fftw::time(fftw_plan_s*, fftw_plan_s*, std::__1::complex<double>*, std::__1::complex<double>*, unsigned int) in Test_BiquadFilter.cpp.o
"fftwpp::fftw::effort", referenced from:
fftwpp::rcfft1d::Plan(std::__1::complex<double>*, std::__1::complex<double>*) in Test_BiquadFilter.cpp.o
fftwpp::crfft1d::Plan(std::__1::complex<double>*, std::__1::complex<double>*) in Test_BiquadFilter.cpp.o
"fftwpp::fftw::planner", referenced from:
fftwpp::fftw::Setup(std::__1::complex<double>*, std::__1::complex<double>*) in Test_BiquadFilter.cpp.o
"fftwpp::inout", referenced from:
fftwpp::fftw::Setout(std::__1::complex<double>*, std::__1::complex<double>*) in Test_BiquadFilter.cpp.o
"fftwpp::crfft1d::threadtable", referenced from:
fftwpp::crfft1d::lookup(bool, unsigned int) in Test_BiquadFilter.cpp.o
fftwpp::crfft1d::store(bool, fftwpp::threaddata const&) in Test_BiquadFilter.cpp.o
"fftwpp::rcfft1d::threadtable", referenced from:
fftwpp::rcfft1d::lookup(bool, unsigned int) in Test_BiquadFilter.cpp.o
fftwpp::rcfft1d::store(bool, fftwpp::threaddata const&) in Test_BiquadFilter.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)
Should I be linking the FFTW library against FFTWPP and be building that as its own library, and then link that library against my project?
I know I have probably added some extra parts to the Cmake project unnecessarily, but is my CMake configuration otherwise incorrect for another reason, when linking a library this way?
Many thanks,
The answer to my issues as kindly pointed out by a commenter to the original post, was that I was not linking against FFTWPP.
The solution in this was to add FFTWPP as a library to the project, and add that library to the list of target linked libraries.
link_directories(./../../../fftwpp/)
find_library(
fftw3
NAMES fftw lfftw3 libfftw3
HINTS /usr/local/lib
)
add_library(fftwpp STATIC ./../../../fftwpp/fftw++.cc)
add_executable(IIR
Test_BiquadFilter.cpp)
target_link_libraries(IIR PUBLIC Python fftw3 fftwpp)
I'm trying to compile https://github.com/dmikushin/binance-cxx-api on osx 10.13.6
(since code is written for linux i had to adjust things a little)
I get following errors (which are openssl related as far as i see):
Undefined symbols for architecture x86_64:
"_EVP_sha256", referenced from:
binance::hmac_sha256(char const*, char const*) in binance_utils.cpp.o
"_HMAC", referenced from:
binance::hmac_sha256(char const*, char const*) in binance_utils.cpp.o
"_SHA256_Final", referenced from:
binance::sha256(char const*) in binance_utils.cpp.o
"_SHA256_Init", referenced from:
binance::sha256(char const*) in binance_utils.cpp.o
"_SHA256_Update", referenced from:
binance::sha256(char const*) in binance_utils.cpp.o
ld: symbol(s) not found for architecture x86_64
The project is cmake based and does not find or link against openssl (installed with homebrew)
I added include and lib dirs directly in the cmake GUI -> compiler, linker flag
(took the include dir, still gave me the errors)
Also applied several combinations of below and alike => didn't make the error go away
cmake -DOPENSSL_INCLUDE_DIR=/usr/local/Cellar/openssl/1.0.2d_1/include -DOPENSSL_CRYPTO_LIBRARY=/usr/local/Cellar/openssl/1.0.2d_1/lib/libcrypto.dylib -DOPENSSL_SSL_LIBRARY=/usr/local/Cellar/openssl/1.0.2d_1/lib/libssl.dylib
googling did not bring up new ideas (most of these errors seem to be fixed by the cmake -DOPENSSL.. option)
Does anyone have an idea?
Did you consider editing the cmake project ?
Adding the following lines in the CMakeLists.txt:
FIND_PACKAGE(OpenSSL)
if(${OpenSSL_FOUND})
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
endif()
And editing the following line to link to OpenSSL
target_link_libraries(${PROJECT_NAME} jsoncpp curl websockets ssl crypto)
Trying to compile my C++ application using clang which works but I get the following linker error:
Undefined symbols for architecture x86_64:
"_DADiskCopyDescription", referenced from:
Security::getHddID() in Security.cpp.o
"_DADiskCreateFromBSDName", referenced from:
Security::getHddID() in Security.cpp.o
"_DASessionCreate", referenced from:
Security::getHddID() in Security.cpp.o
ld: symbol(s) not found for architecture x86_64
I've checked the official documentation for Disk Arbitration on the Apple website but that's awful, since it doesn't even tell you which library file to include, let alone what to link to.
I'm using CMake to set up my build chain.
You need to use -framework DiskArbitration in your linker arguments.
I want to write common code that work for both iPhone and android. For that I want to use cURL library that work fine for android but for iOS it gives me following error:
(null): "_curl_easy_cleanup", referenced from:
(null): "_curl_easy_init", referenced from:
(null): "_curl_easy_perform", referenced from:
(null): "_curl_easy_setopt", referenced from:
(null): "_curl_easy_strerror", referenced from:
(null): Linker command failed with exit code 1 (use -v to see invocation)
Above error indicate some linking error for libcurl.a. I am not able to find out proper solution. Please help.
Have you added libcurl.a to the linking process of your app's compilation in XCode? If this were GCC it would be by adding a flag like -lcurl but I am not too sure about XCode.
Try this:
XCode -> Click on your project -> Your Target -> Build Settings -> Linking -> other Linker flags - here add -lcurl
The path to the library might need to be added in Build Settings -> Search paths -> Library Search Paths
I am trying to compile some stuff under mac os 10.7 in eclipse and the build dies on:
Undefined symbols for architecture x86_64:
"_kCFAllocatorDefault", referenced from:
___GLeeGetProcAddress in GLee.o
"_CFURLCreateWithFileSystemPath", referenced from:
___GLeeGetProcAddress in GLee.o
"_CFStringCreateWithCString", referenced from:
___GLeeGetProcAddress in GLee.o
"_CFBundleCreate", referenced from:
___GLeeGetProcAddress in GLee.o
"_CFBundleGetFunctionPointerForName", referenced from:
___GLeeGetProcAddress in GLee.o
"_CFRelease", referenced from:
___GLeeGetProcAddress in GLee.o
"_glGetString", referenced from:
___GLeeGetExtensions in GLee.o
_GLeeGetExtStrGL in GLee.o
_GLeeInit in GLee.o
(maybe you meant: _GLee_Lazy_glGetStringi, _GLeeFuncPtr_glGetStringi )
"___CFConstantStringClassReference", referenced from:
CFString in GLee.o
So I know the problem is with ld symbols. Now I tried going to project proprieties and adding -framework CoreFramework to parameters of g++ and gcc in eclipse but that didnt fix it.
Where are these symbols located and more importantly - how do I add them to my project?
I fixed this by adding a .dylib to linker. How to set it up?
Go to project proprieties
Go to C/C++ build --> settings
Choose Mac OS X C++ Linker --> Libraries
Here is where the tricky part is... I found out by "try-error" method, how this works:
Lets say you have a dylib file you want to add called "libMyLib.dylib" located in /opt/local/lib/MyLibrary
To part of the window where it says libraries add line
"MyLib"
To part of the window where it says Library search path add line
"/opt/local/lib/MyLibrary/"
=> eclipse will automatically do this:
1. add "lib" in front of the string
2. add ".dylib" after your string
There comes another problem with Mac... Lets say you use symbols from CoreFoundation framework. Mac OS frameworks are essentialy dylibs with header files ... If you are not sure you can always check by "file myFile"
The problem is that eclipse will never correctly pick up on those dylibs from MAC OS SDK and /System/Library/Frameworks/ cause they dont have the .dylib added to them. The trick is to simply go to where the dylib is located (eventhough it doesnt have a .dylib in its name) e.g.
cd /System/Library/Frameworks/CoreFoundation.framework
and then copy the file and add dylib (do NOT RENAME IT!!!)
file CoreFoundation
CoreFoundation (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
CoreFoundation (for architecture i386): Mach-O dynamically linked shared library i386
#copy the lib and name it to "eclipse friendly format"
cp CoreFoundation libCoreFoundation.dylib
You can use the -framework option
e.g. g++ -framework CoreFoundation ..........