Xcode Linker Flags Stanford Network Analysis Project (SNAP) - c++

I am trying to SNAP with C++ on Xcode. I installed SNAP and provided these two header search paths to Xcode: /usr/local/Cellar/Snap-3.0/snap-core/ and /usr/local/Cellar/Snap-3.0/glib-core/.
But it still produces the error below. I believe I need to fill in "other linker flags" in Xcode, but I can't seem to get it right. Thanks for help.
The C++ Code is below:
#include "Snap.h"
int main() {
return 0;
}
Error Message Below
Undefined symbols for architecture x86_64:
"ExeStop(char const*, char const*, char const*, char const*, int const&)", referenced from:
TRStr::UnRef() in main.o
TRStr::~TRStr() in main.o
TRStr::GetNullRStr() in main.o
"TStr::GetRStr(char const*)", referenced from:
TStr::TStr(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)**

It works once I add -lSnap.o in "other linker flags" in Xcode

Related

Number Theory Library (NTL) on Mac Xcode - c++ - (Undefined symbols for architecture x86_64) Linker error - Apple Mach-O Linker (ld) Error Group

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

Linking external code in XCode

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)

Xcode 5.1.1 and Boost

Problem was solved by adding .dylib files (boost) to project.
I'm trying connect Boost 1.55 to Xcode 5 through Homebrew.
Brew installed it as it should. In /usr/local/include && /usr/local/lib appeared aliases on Boost headers and libraries.
Xcode "Search Path" settings:
http://i.imgur.com/j5GJ0sh.png
http://i.imgur.com/DXRxiyA.png
But when I tried compile simple example:
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <boost/regex.hpp>
using namespace std;
using namespace boost;
int main()
{
const regex expression( "How to re" );
string string1 = "How to re";
bool match=regex_match(string1,expression);
if (match){
cout<<"Yes"<<endl;
}
return 0;
}
Errors:
Undefined symbols for architecture x86_64: "boost::basic_regex >
::do_assign(char const*, char const*, unsigned int)", referenced from:
boost::basic_regex > >::assign(char const*, char const*,
unsigned int) in main.o "boost::re_detail::get_mem_block()",
referenced from:
boost::re_detail::perl_matcher,
std::__1::allocator > >, boost::regex_traits >
::extend_stack() in main.o
boost::re_detail::save_state_init::save_state_init(boost::re_detail::saved_state**,
boost::re_detail::saved_state**) in main.o
"boost::re_detail::put_mem_block(void*)", referenced from:
boost::re_detail::save_state_init::~save_state_init() in main.o
boost::re_detail::perl_matcher,
std::__1::allocator > >, boost::regex_traits >
::unwind_extra_block(bool) in main.o "boost::re_detail::verify_options(unsigned int,
boost::regex_constants::_match_flags)", referenced from:
boost::re_detail::perl_matcher,
std::__1::allocator > >, boost::regex_traits >
::match_imp() in main.o "boost::re_detail::raise_runtime_error(std::runtime_error const&)",
referenced from:
void boost::re_detail::raise_error > >
(boost::regex_traits_wrapper > > const&,
boost::regex_constants::error_type) in main.o
"boost::re_detail::get_default_error_string(boost::regex_constants::error_type)",
referenced from:
boost::re_detail::cpp_regex_traits_implementation::error_string(boost::regex_constants::error_type)
const in main.o
"boost::re_detail::cpp_regex_traits_implementation::transform_primary(char const*, char const*) const", referenced from:
boost::cpp_regex_traits::transform_primary(char const*, char const*) const in main.o
"boost::re_detail::cpp_regex_traits_implementation::transform(char
const*, char const*) const", referenced from:
boost::cpp_regex_traits::transform(char const*, char const*) 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)
Really tired with it, so, ask for your help.
Thank you,
- Philipp
You have a few options but all of them involve adding the library libboost_regex to your project to resolve the link errors. Even though you installed boost using homebrew, you still need to add the library to your project because boost's regex code contains a compiled portion. If you don't add the library there is no way for the linker to resolve the symbols.
The first option is to add /usr/local/lib to Library Search Paths, and add -lboost_regex to Other Linker Flags. If you choose this option you may need to add /usr/local/lib to Runpath Search Paths also. This method will link against the dynamic library in /usr/local/lib.
If you want your program to be self-contained you can link against the static (.a) version of boost_regex. To do this add libboost_regex.a to your project in Build Settings - Link Binary With Libraries.

g++ ld: symbol(s) not found for architecture x86_64

I'm trying to compile the Sam Hare's Struck code.
I'm using mac OSX10.9, opencv 2.4.6 and Eigen 2.0.17.
Eigen and opencv headers are stored in /opt/local/include while opencv dylib in /opt/local/lib.
I modified the Hare's Makefile to work on this folder. When I type make on the terminal:
g++ -L/opt/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc src/Config.o src/Features.o src/HaarFeature.o src/HaarFeatures.o src/HistogramFeatures.o src/ImageRep.o src/LaRank.o src/MultiFeatures.o src/RawFeatures.o src/Sampler.o src/Tracker.o src/main.o src/GraphUtils/GraphUtils.o -o struck
I get these errors:
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&,
int)", referenced from:
_main in main.o "cv::split(cv::Mat const&, std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)",
referenced from:
ImageRep::ImageRep(cv::Mat const&, bool, bool, bool) in ImageRep.o "cv::imread(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&,
int)", referenced from:
_main in main.o "cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&,
cv::_InputArray const&)", referenced from:
LaRank::Debug() in LaRank.o
Tracker::Debug() in Tracker.o
_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)
Any ideas? Thanks!
I had a similar warning/error/failure when I was simply trying to make an executable from two different object files (main.o and add.o). I was using the command:
gcc -o exec main.o add.o
But my program is a C++ program. Using the g++ compiler solved my issue:
g++ -o exec main.o add.o
I was always under the impression that gcc could figure these things out on its own. Apparently not. I hope this helps someone else searching for this error.
finally solved my problem.
I created a new project in XCode with the sources and changed the C++ Standard Library from the default libc++ to libstdc++ as in this and this.
I am getting the same error. I don't think it is a "fix", but my work-around is to also include the cpp file. So instead of just putting
#include "MyClass.h"
I have to put
#include "MyClass.h"
#include "MyClass.cpp"
I wrote my declarition in the .h file
class String
{
String (const char * cstr = 0);
};
and I used inline in another .cpp file (implementation)
inline String::String(const char * cstr)
{
//code ...
}
then I use g++ and get this:
Undefined symbols for architecture x86_64:
"String::String(char const*)", referenced from:
_main in test-d389f3.o
ld: symbol(s) not found for architecture x86_64
solution: do not write inline when declarition and implementation is independent.
When I using clang to compile a C++ program, I have the similar error.
But after I changing to use chang++, the compilation worked.

how to install Openmpi for xcode?

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