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.
Related
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
$clang++ main.cpp -o out
Got following error, the same error happens when changing to g++. I have tested on some simple simple c++ code, the command works fine. So it the problem in that PNG class file? However, the same files worked on my MacOS before, but suddenly failed today.
Undefined symbols for architecture x86_64:
"PNG::writeToFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in main-f6a06a.o
"PNG::PNG(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in main-f6a06a.o
"PNG::PNG(unsigned long, unsigned long)", referenced from:
_main in main-f6a06a.o
"PNG::~PNG()", referenced from:
_main in main-f6a06a.o
"PNG::operator()(unsigned long, unsigned long)", referenced from:
_main in main-f6a06a.o
"PNG::width() const", referenced from:
_main in main-f6a06a.o
"PNG::height() const", referenced from:
_main in main-f6a06a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Did you miss providing static/shared to the linker to resolve the linker errors for the methods mentioned? Also note that clang++ is a different compiler compared to g++ and hence need the static/shared libraries compiled prior by the same compiler you are using (clang++).
Try:
clang++ main.cpp -o out -lpng
Here's why: You are not providing the library that contains the implementation of your PNG library (libpng most likely). You need -lpng added to your compiler, so that it links with the relevant library. It may not be exactly -lpng in your particular case, but it's definitely a "missing library". Without knowing exactly what library you are trying to use (you didn't provide some source to "try the fix with").
As pointed out in the comment: you are using some kind of C++ wrapper on top, the above is probably not enough - but without knowing exactly which C++ wrapper on the png functionality you are actually using, it's hard to say what the command-line should look like.
Perhaps this
I'm having some trouble compiling a basic program using RtMidi on OS X. I initially tried using XCode and adding the library as a target, then I tried a simpler compilation using g++. The same errors were returned in each instance.
Here's the command and output:
$ g++ -Wall -D __MACOSX_CORE__ -o midiprobe midiprobe.cpp -framework CoreAudio -framework CoreFoundation -lpthread
Undefined symbols for architecture x86_64:
"RtMidiIn::RtMidiIn(RtMidi::Api, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned int)", referenced from:
_main in midiprobe-d2b0ea.o
"RtMidiOut::RtMidiOut(RtMidi::Api, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
_main in midiprobe-d2b0ea.o
ld: symbol(s) not found for architecture x86_64
This is my first time using a library in this manner, so some pointers in the right direction would be appreciated. Thanks!
I am new to cpp, want to have a implementation of particle filter, I try to run the code here https://github.com/NewProggie/Particle-Filter, which is a structured and easy understanding project. But when I try to compile and link:
g++ $(pkg-config --cflags --libs opencv) -I/usr/local/Cellar/opencv3/3.1.0_1/include -I /usr/local/Cellar/gsl/1.16/include -stdlib=libc++ main.cpp -o main
I have following linking problem:
Undefined symbols for architecture x86_64:
"colorFeatures::colorFeatures()", referenced from:
_main in main-2b4c23.o
"colorFeatures::~colorFeatures()", referenced from:
_main in main-2b4c23.o
"adaboostDetect::detectObject(_IplImage*, CvRect**)", referenced from:
_main in main-2b4c23.o
"adaboostDetect::adaboostDetect()", referenced from:
_main in main-2b4c23.o
"tracker::addObjects(_IplImage*, CvRect*, int)", referenced from:
_main in main-2b4c23.o
"tracker::initTracker(_IplImage*, CvRect*, int, int)", referenced from:
_main in main-2b4c23.o
"tracker::showResults(_IplImage*)", referenced from:
_main in main-2b4c23.o
"tracker::next(_IplImage*)", referenced from:
_main in main-2b4c23.o
"tracker::tracker()", referenced from:
_main in main-2b4c23.o
"tracker::~tracker()", referenced from:
_main in main-2b4c23.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 kind person has ideas about this problem? Thanks in advance
have gsl installed properly
B) pass to g++ a reference to the lib directory where the gsl libraries are located (probably something like /usr/lib or /usr/local/lib, these should both be default locations for the linker to search), and also to where the header files are, and also tell the linker to do the linking.
g++ -o <name of executable> -L/path/to/gsl/libs -I/path/to/headers -lgsl <name of source file>
the -L tells it where to find the libraries (.so files on linux, .dylib on OS X), -I tells it where to find the headers, -l (that's a lower case L) tells it to link to the library, which would be named libgsl.so or libgsl.dylib.
First just try adding the -lgsl flag, then if it can't find libgsl.so (or .dylib), add the -L flag. NOTE: /path/to/gsl/libs and /path/to/headers are not what you should literally put in there, but replace them with the actual paths on your system.
First of all, I've read the related content on Stackoverflow on this problem but I still can't solve it. I've simplified my code as much as possible.
I've only a custom class with .h and .cpp files but I get error while trying to create an instance of this class from main.cpp.
main.cpp
#include "Customer.h"
using namespace std;
int main() {
Customer a("string");
return 0;
}
Customer.h
using namespace std;
class Customer {
public:
Customer(string input);
};
Customer.cpp
#include "Customer.h"
using namespace std;
Customer::Customer(string input) {
}
The error message I get is the following?
gcc *.cpp -o k
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
_main in main-40340f.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in main-40340f.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
_main in main-40340f.o
"std::terminate()", referenced from:
___clang_call_terminate in main-40340f.o
"___cxa_begin_catch", referenced from:
___clang_call_terminate in main-40340f.o
"___gxx_personality_v0", referenced from:
_main in main-40340f.o
Dwarf Exception Unwind Info (__eh_frame) in main-40340f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I run Mac OS X 10.9 and Sublime Text 3. gcc -v gives the following:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
It compiles without problem when I write empty constructors instead of these.
What could cause this problem?
Two problems:
You should #include <string>.
To compile C++ code on OS X, use clang++ or g++.
Use g++ instead of gcc:
$ g++ *.cpp -o k
and then the compiler driver knows to link-in the C++ runtime library. Given it's actually clang you are using, and not gcc, then this is better:
$ clang++ *.cpp -o k
Use "g++ "instead of "gcc" to compile and link your application. It automatically knows about the C++ libraries that need to be included.
You need to install Command Line Tools.
https://developer.apple.com/downloads/
g++ main.cpp(or Customer.cpp) -o k is not enough. You should compile them at the same time.
"g++ main.cpp Customer.cpp (and other *.cpp(s) if you have) -o target "
will work well.