I have Simple c++ Code that works fine while also using #include "engine.h" for the use of MATLAB in the c++ code.I am also using some functions like mxArray(), mxCreateDoubleMatrix() & mxSetPr(). After going to terminal and compiling the code with g++ -o main main.cpp the following errors occur
Undefined symbols for architecture x86_64:
"_engClose", referenced from:
_main in main-438cf4.o
"_engEvalString", referenced from:
_main in main-438cf4.o
"_engOpen", referenced from:
_main in main-438cf4.o
"_engPutVariable", referenced from:
_main in main-438cf4.o
"_mxCreateDoubleMatrix_730", referenced from:
_main in main-438cf4.o
"_mxSetPr", referenced from:
_main in main-438cf4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I don't think I need to put my actual code here since I am assuming this error has to do with compatibility issues not the code itself. If i'm wrong I will edit the post
P.S. I am using os Sierra. ( i have also tried compiling with xcode 9.0.1, same errors occur)
Thanks
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 2 years ago.
I'm trying to compile using SDL2 library with no success.
OS: MacOS 10.13.2
Visual Studio Code 1.43.1
Language: c++
I'm using the Lazy Foo's very basic example code.
This is the message I recieve:
[Running] cd "/Users/martinjoselizondocolomes/Programacion/01_hello_SDL/" && g++ 01_hello_SDL.cpp -o 01_hello_SDL && "/Users/martinjoselizondocolomes/Programacion/01_hello_SDL/"01_hello_SDL
Undefined symbols for architecture x86_64:
"_SDL_CreateWindow", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_Delay", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_DestroyWindow", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_FillRect", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_GetError", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_GetWindowSurface", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_Init", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_MapRGB", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_Quit", referenced from:
_main in 01_hello_SDL-a16d96.o
"_SDL_UpdateWindowSurface", referenced from:
_main in 01_hello_SDL-a16d96.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[Done] exited with code=1 in 0.168 seconds
Building C++ code requires three stages:
Preprocessor deals with macros and #include directives, so your header files are required at this step.
Compiler generates object files. This is the point when the syntax is checked in your source files.
Linker combines object files and libraries into an executable so your runtime libraries must be available and specified to the linker.
For g++, you specify libraries by giving their full name on the command line or use the -l shortcut which figures out the proper prefix (lib) and suffix. So in your case I believe you can add -lSDL.
EDIT: If that doesn't work, check the output of
sdl-config --libs
$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 am trying to make a C application on OSX(10.9.5) which will connect to mongodb and perform CRUD operations. I am using the release 1.3.5 which I downloaded from: https://github.com/mongodb/mongo-c-driver/releases/tag/1.3.5
I was sucessfully able to install mongo on my system. I am making my application which will use the library to perform CRUD operations. I am using Xcode 6.1.1 as my IDEon osx. I have given the appropriate path for header files in the ide and have no warnings or error before the run. I have given search path for dynamic libraries as well so I think linking should be happening fine as well. However when I try to run I get the following error:
Undefined symbols for architecture x86_64:
"_bson_as_json", referenced from:
_main in find.o "_bson_destroy", referenced from:
_main in find.o "_bson_free", referenced from:
_main in find.o "_bson_new", referenced from:
_main in find.o "_mongoc_cleanup", referenced from:
_main in find.o "_mongoc_client_destroy", referenced from:
_main in find.o "_mongoc_client_get_collection", referenced from:
_main in find.o "_mongoc_client_new", referenced from:
_main in find.o "_mongoc_collection_destroy", referenced from:
_main in find.o "_mongoc_collection_find", referenced from:
_main in find.o "_mongoc_cursor_destroy", referenced from:
_main in find.o "_mongoc_cursor_next", referenced from:
_main in find.o "_mongoc_init", referenced from:
_main in find.o ld: symbol(s) not found for architecture x86_64 clang:error: linker command failed with exit code 1 (use -v to see invocation)
Where am I going wrong?
Looks like you've specified the dynamic library path for libmongoc-1.0.so but not the library it depends on, libbson-1.0.so. Both libraries were installed when you built the driver, so you should be able to specify an additional path and your program will link correctly.
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.
I'm trying to get up to speed using libcurl with D on Mac.
I'm using the latest dmd2 compiler (DMD64 D Compiler v2.062).
The following example compiles and works fine on Windows:
import std.net.curl, std.conv, std.stdio;
void main() {
string content = to!string(get("dlang.org"));
writeln(content);
}
When compiling it on Mac I get the following output:
~/src $ dmd dcurl.d
Undefined symbols for architecture x86_64:
"_curl_easy_cleanup", referenced from:
_D3std3net4curl4Curl8shutdownMFZv in libphobos2.a(curl_1522_37c.o)
"_curl_easy_duphandle", referenced from:
_D3std3net4curl4Curl3dupMFZS3std3net4curl4Curl in libphobos2.a(curl_151e_149.o)
"_curl_easy_init", referenced from:
_D3std3net4curl4Curl10initializeMFZv in libphobos2.a(curl_151d_432.o)
"_curl_easy_perform", referenced from:
_D3std3net4curl4Curl7performMFbZi in libphobos2.a(curl_1528_2fb.o)
"_curl_easy_setopt", referenced from:
_D3std3net4curl4Curl3setMFE3etc1c4curl10CurlOptionlZv in libphobos2.a(curl_1525_14c.o)
_D3std3net4curl4Curl3setMFE3etc1c4curl10CurlOptionAxaZv in libphobos2.a(curl_1524_14c.o)
_D3std3net4curl4Curl3setMFE3etc1c4curl10CurlOptionPvZv in libphobos2.a(curl_1526_14c.o)
_D3std3net4curl4Curl5clearMFE3etc1c4curl10CurlOptionZv in libphobos2.a(curl_1527_207.o)
"_curl_easy_strerror", referenced from:
_D3std3net4curl4Curl11errorStringMFiZAya in libphobos2.a(curl_1520_4a1.o)
"_curl_global_cleanup", referenced from:
_D3std3net4curl4Curl19_sharedStaticDtor29FZv in libphobos2.a(curl.o)
"_curl_global_init", referenced from:
_D3std3net4curl4Curl19_sharedStaticCtor28FZv in libphobos2.a(curl.o)
"_curl_slist_append", referenced from:
_D3std3net4curl3FTP3dupMFZS3std3net4curl3FTP in libphobos2.a(curl_1518_ea.o)
_D3std3net4curl3FTP10addCommandMFAxaZv in libphobos2.a(curl_1518_ea.o)
_D3std3net4curl4HTTP3dupMFZS3std3net4curl4HTTP in libphobos2.a(curl_1517_140.o)
_D3std3net4curl4HTTP16addRequestHeaderMFAxaAxaZv in libphobos2.a(curl_1517_140.o)
"_curl_slist_free_all", referenced from:
_D3std3net4curl3FTP4Impl6__dtorMFZv in libphobos2.a(curl_1518_ea.o)
_D3std3net4curl3FTP13clearCommandsMFZv in libphobos2.a(curl_1518_ea.o)
_D3std3net4curl4HTTP4Impl6__dtorMFZv in libphobos2.a(curl_1517_140.o)
_D3std3net4curl4HTTP19clearRequestHeadersMFZv in libphobos2.a(curl_1517_140.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
--- errorlevel 1
Which seems to imply a linking issue.
I have libcurl at:
/usr/lib/libcurl.3.dylib /usr/lib/libcurl.4.dylib /usr/lib/libcurl.dylib
But I'm not even sure whether dmd is trying to use them.
I've done this before with C/C++ (on the same machine using these libraries) so I think it must be a versioning issue or else I need to pass some flags to the compiler.
Any help would be most appreciated.
You need to link against libcurl. It's not linked against by default. So, instead of
dmd dcurl.d
you need to do
dmd -L-lcurl dcurl.d