I'm working with an external code in my project which I have access to the headers and the .cc files but I don't have any access to .dylibs. I'm getting some errors, related to link of the libs, that is described bellow.
This code runs perfectly well if I run it directly from the terminal. The problem only occured when I tried to incorporate it on my own project (that have other modules) in XCode. I guess that if I add the .dylib files to XCode it will solve the problem. However, I don't have the .dylibs. How can I put this code to run?
Undefined symbols for architecture x86_64:
"FACETRACKER::IO::LoadCon(char const*)", referenced from:
mark(int, char const**) in main.o
"FACETRACKER::IO::LoadTri(char const*)", referenced from:
mark(int, char const**) in main.o
"FACETRACKER::CLM::GetViewIdx()", referenced from:
mark(int, char const**) in main.o
"FACETRACKER::FDet::~FDet()", referenced from:
FACETRACKER::Tracker::~Tracker() in main.o
FACETRACKER::Tracker::Tracker(char const*) in main.o
"FACETRACKER::Tracker::Load(char const*)", referenced from:
FACETRACKER::Tracker::Tracker(char const*) in main.o
"FACETRACKER::Tracker::Track(cv::Mat, std::__1::vector<int, std::__1::allocator<int> >&, int, int, double, double, bool)", referenced from:
mark(int, char const**) 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)
Related
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I'm not sure if I have a problem w/ requiring additional arguments to cmake, or a problem with my own Makefiles. I am trying to build and install googletest for use in one of my projects. I am running on macOS mojave, with cmake installed via Homebrew. To install googletest, I have done the following:
git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
make install
I compile my source and test files. Here is an example command that gets generated by the Makefile for compiling a file named Point2d.cpp:
clang++ -arch x86_64 -c -std=c++11 -stdlib=libc++ -O2 -I /usr/local/include -c -o ../build/core/Point2d.o core/Point2d.cpp
I then try to link all my object files. Here is the command generated by the makefile (where main.o is the object file containing the main function for running the tests):
clang++ -arch x86_64 ../build/core/Point2d.o ../build/PointTest.o ../build/main.o -o ../bin/test -L /usr/local/lib
Resulting link error:
Undefined symbols for architecture x86_64:
"testing::InitGoogleTest(int*, char**)", referenced from:
_main in main.o
"testing::Test::SetUp()", referenced from:
vtable for Point2dTests_Constructors_Test in PointTest.o
"testing::Test::TearDown()", referenced from:
vtable for Point2dTests_Constructors_Test in PointTest.o
"testing::Test::Test()", referenced from:
testing::internal::TestFactoryImpl<Point2dTests_Constructors_Test>::CreateTest() in PointTest.o
"testing::Test::~Test()", referenced from:
Point2dTests_Constructors_Test::~Point2dTests_Constructors_Test() in PointTest.o
Point2dTests_Constructors_Test::~Point2dTests_Constructors_Test() in PointTest.o
"testing::Message::Message()", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::UnitTest::GetInstance()", referenced from:
_main in main.o
"testing::UnitTest::Run()", referenced from:
_main in main.o
"testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::internal::AssertHelper::~AssertHelper()", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::internal::GetTestTypeId()", referenced from:
__GLOBAL__sub_I_PointTest.cpp in PointTest.o
"testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)", referenced from:
__GLOBAL__sub_I_PointTest.cpp in PointTest.o
"testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::internal::IsTrue(bool)", referenced from:
testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in PointTest.o
testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in PointTest.o
"testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)", referenced from:
testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in PointTest.o
testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in PointTest.o
"testing::internal::GTestLog::~GTestLog()", referenced from:
testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in PointTest.o
testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in PointTest.o
"testing::internal::AssertHelper::operator=(testing::Message const&) const", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"typeinfo for testing::Test", referenced from:
typeinfo for Point2dTests_Constructors_Test in PointTest.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[1]: *** [../bin/test] Error 1
make: *** [test] Error 2
Solved. Please see the comments of the question, posted by #AlexDenisov
I have used "brew install ntl" on mac.
If I use libc++ in Xcode I get the following linking errors:
Undefined symbols for architecture x86_64: "_ntl_gcopy(_ntl_gbigint_body*, _ntl_gbigint_body**)", referenced from: NTL::ZZ::operator=(NTL::ZZ&&) in main.o "_ntl_gfree(_ntl_gbigint_body*)", referenced from: NTL::ZZ::Deleter::apply(_ntl_gbigint_body*) in main.o "_ntl_gsadd(_ntl_gbigint_body*, long, _ntl_gbigint_body**)", referenced from: NTL::add(NTL::ZZ&, NTL::ZZ const&, long) in main.o "_ntl_gmul(_ntl_gbigint_body*, _ntl_gbigint_body*, _ntl_gbigint_body**)", referenced from: NTL::mul(NTL::ZZ&, NTL::ZZ const&, NTL::ZZ const&) in main.o "NTL::operator<<(std::__1::basic_ostream >&, NTL::ZZ const&)", referenced from: _main in main.o "NTL::operator>>(std::__1::basic_istream >&, NTL::ZZ&)", 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)
If I switch to libstdc++ as in: GCC 4.7/4.8 as Xcode's C/C++ Compiler I get 'type_traits' file not found. The however does solve the other linker errors.
How do I use the NTL library in Xcode otherwise? Do I have to add 'other linker flags', and if so, how and which ones?
NTL version 11.1.0
I am testing out eclipse C++ for Mac. I have three specific questions.
This is the classic iostream problem for Mac. It does not know where to find it. So in the project properties I add the path where iostream is located (Preferences->C/C++ General->Paths and Symbols->includes). Now iostream works. But I am trying to find a way where I don't have to do this for every new project. Is there a specific setting I can select to include this directory automatically for each new project?
Is xCode necessary for eclipse to work? If yes, how can I get eclipse to work without it? xCode takes up 6 GBs.
I'm getting an error on a test project (see below) that I'm not sure how to fix. Something about "linker command failed". I seem to be able to compile regular C programs fine though. Note this project works fine in Visual Studio.
23:37:30 **** Incremental Build of configuration Debug for project pointClass ****
make all
Building target: pointClass
Invoking: MacOS X C++ Linker
g++ -o "pointClass" ./point.o ./test.o
Undefined symbols for architecture x86_64:
"std::istream::operator>>(double&)", referenced from:
_main in test.o
"std::ostream::operator<<(std::ostream& ()(std::ostream&))", referenced from:
_main in test.o
Point::Point(double, double) in test.o
Point::Point(Point const&) in test.o
"std::ostream::operator<<(double)", referenced from:
_main in test.o
Point::Point(double, double) in test.o
"std::basic_string, std::allocator >::~basic_string()", referenced from:
_main in test.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in test.o
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in test.o
"std::cin", referenced from:
_main in test.o
"std::cout", referenced from:
_main in test.o
Point::Point(double, double) in test.o
Point::Point(Point const&) in test.o
"std::basic_ostream >& std::endl >(std::basic_ostream >&)", referenced from:
_main in test.o
Point::Point(double, double) in test.o
Point::Point(Point const&) in test.o
"std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const)", referenced from:
_main in test.o
Point::Point(double, double) in test.o
Point::Point(Point const&) in test.o
"std::basic_ostream >& std::operator<<, std::allocator >(std::basic_ostream >&, std::basic_string, std::allocator > const&)", referenced from:
_main in test.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: *** [pointClass] Error 1
I am trying to run an opencv project by xcode6.
This tutorial is cool and works for me, first, without xcode: The application runs perfectly after make'ing.
Now, I want to use Xcode 6 as development environment.
But I get an Apple Mach-O Linker error.
Build Settings are:
Header Search Paths : /usr/local/include (non-recursive)
Library Search Paths: /urs/local/lib (non-recursive)
Build Phases > Link Binary With Libraries:
Libc++.dylib
This is the error:
Ld /Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Products/Debug/HelloWorld normal x86_64
cd /Users/XXX/Desktop/make/CLTproject/HelloWorld/HelloWorld
export MACOSX_DEPLOYMENT_TARGET=10.10
/Applications/Xcode-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Products/Debug -L/usr/local/lib -F/Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Products/Debug -filelist /Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/HelloWorld.LinkFileList -mmacosx-version-min=10.10 -stdlib=libc++ -lc++ -Xlinker -dependency_info -Xlinker /Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/HelloWorld_dependency_info.dat -o /Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Products/Debug/HelloWorld
Undefined symbols for architecture x86_64:
"cv::namedWindow(cv::String const&, int)", referenced from:
_main in main.o
"cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
_main in main.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in main.o
"cv::Mat::copySize(cv::Mat const&)", referenced from:
cv::Mat::operator=(cv::Mat const&) in main.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in main.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(char const*) in main.o
"cv::imread(cv::String const&, int)", referenced from:
_main in main.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
_main in main.o
"cv::waitKey(int)", referenced from:
_main in main.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in main.o
"cv::Mat::copyTo(cv::_OutputArray const&) const", referenced from:
cv::Mat::clone() const in main.o
"vtable for cv::_InputArray", referenced from:
cv::_InputArray::_InputArray() in main.o
cv::_InputArray::_InputArray(cv::Mat const&) in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for cv::_OutputArray", referenced from:
cv::_OutputArray::_OutputArray(cv::Mat&) in main.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)
Any Idea?
Thanks,
isicom
Just to give some light to everybody in the same problem. I added all libraries and worked fine for me. I stayed in the libc++ with no building errors.
I'm trying to run some MPI programs in xcode 4. I installed openmpi from MacPort by typing sudo port install openmpi and the installation finished normally. Then I added opt/local/include/openmpi to my user header search paths, dragged the "libmpi.dylib" and "libmpi_cxx.dylib" into my project.
But then when I tried to run the program, I got the following error message:
Undefined symbols for architecture x86_64:
"_MPI_Comm_accept", referenced from:
MPI::Intracomm::Accept(char const*, MPI::Info const&, int) const in main.o
"_MPI_Comm_connect", referenced from:
MPI::Intracomm::Connect(char const*, MPI::Info const&, int) const in main.o
"_MPI_Comm_disconnect", referenced from:
MPI::Comm::Disconnect() in main.o
"_MPI_Comm_get_errhandler", referenced from:
MPI::Comm::Get_errhandler() const in main.o
"_MPI_Comm_set_errhandler", referenced from:
MPI::Comm::Set_errhandler(MPI::Errhandler const&) const in main.o
"_MPI_Comm_spawn", referenced from:
MPI::Intracomm::Spawn(char const*, char const**, int, MPI::Info const&, int) const in main.o
MPI::Intracomm::Spawn(char const*, char const**, int, MPI::Info const&, int, int*) const in main.o
"_MPI_Comm_spawn_multiple", referenced from:
MPI::Intracomm::Spawn_multiple(int, char const**, char const***, int const*, MPI::Info const*, int) in main.o
MPI::Intracomm::Spawn_multiple(int, char const**, char const***, int const*, MPI::Info const*, int, int*) in main.o
"_MPI_Grequest_complete", referenced from:
MPI::Grequest::Complete() in main.o
"_MPI_Op_commutative", referenced from:
MPI::Op::Is_commutative() const in main.o
"_MPI_Reduce_local", referenced from:
MPI::Op::Reduce_local(void const*, void*, int, MPI::Datatype const&) const in main.o
"_MPI_Win_call_errhandler", referenced from:
MPI::Win::Call_errhandler(int) const in main.o
"_MPI_Win_get_errhandler", referenced from:
MPI::Win::Get_errhandler() const in main.o
"_MPI_Win_set_errhandler", referenced from:
MPI::Win::Set_errhandler(MPI::Errhandler const&) const in main.o
"_ompi_mpi_comm_null", referenced from:
MPI::Intracomm::Intracomm(ompi_communicator_t*) in main.o
MPI::Graphcomm::Graphcomm(ompi_communicator_t* const&) in main.o
MPI::Cartcomm::Cartcomm(ompi_communicator_t* const&) in main.o
"_ompi_mpi_comm_world", referenced from:
_main in main.o
"_ompi_mpi_double", referenced from:
_main in main.o
"_ompi_mpi_op_sum", referenced from:
_main in main.o
"_ompi_op_set_cxx_callback", referenced from:
MPI::Op::Init(void (*)(void const*, void*, int, MPI::Datatype const&), bool) 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)
Am I missing anything in the above installation processes?
First be sure to have installed MPI.
I personally use brew to do so.
brew update
brew install open-mpi
Then check the requirements for c++:
mpic++ -showme
or mpicc -showme for c
My output with mpic++ is :
clang++ -I/usr/local/Cellar/open-mpi/1.8.6/include -L/usr/local/opt/libevent/lib -L/usr/local/Cellar/open-mpi/1.8.6/lib -lmpi_cxx -lmpi
Then we got the include path, library path and some other flags. From the output of the previous command we got that we need to add:
"/usr/local/Cellar/open-mpi/1.8.6/include" in the “Search Paths – Header Search Paths”
"/usr/local/opt/libevent/lib" and "/usr/local/Cellar/open-mpi/1.8.6/lib" in the “Search Paths – Library Search Paths”
"-lmpi_cxx -lmpi" in the “Linking – Other Linker Flags”
These can be done through the Build Settings option from the Xcode project.
Because mpi need to use it's own program to run ours we need to change the Executable.
Select "Edit schemes"
In the dialog box under Info for the Executable choose Other... from the combobox.
Change it to mpiexec wich is an alias of "orterun". For me it's in /usr/local/Cellar/open-mpi/1.8.6/bin. Note that this is usually an hidden folder. You can open it by pressing cmd + shift + g.
For running mpiexec need to know as arguments the number of processors and the executable file. So, in the same dialog box under Arguments
add "-n X" where X is the number of processors you want to use "for this example i will use 2".
add "$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH" wich is the combination of environment variables that specify the executable file.
Then add <mpi.h> header to your source code.
Run it and you will see 2 "Hello, World!" (because I use -n 2 for the example).
sources : open-mpi xcode FAQ, Debugging & running MPI programs in Xcode
I had the same problem, when I compiled openmpi from the sources, added header and library search paths, but forgot to add libraries as the linker flags to the build settings. Adding them solved this. You can type mpicc –showme to see the libraries that are necessary for mpi to run.
Or just type mpic++ instead of mpicc. That worked for me ;)