I have compiled libFLAC from source code under macintosh os x 10.6.8 and tested WAV to FLAC conversion with success (from the command line). I have also used the default build as such: ./configure --prefix="$base/flac/more/" --exec-prefix="$base/flac/main/" --disable-asm-optimizations && make && make install
Now after adding the paths for FLAC headers and the libs into a brand new project. I am attempting to decode and load FLAC audio into system memory using libFLAC, under the example code which was bundled with libFLAC. However i am getting symbols not found errors with Standard C and vtable symbols not found errors with the Standard C++ approach (as seen below).
Errors under the C approach:
"FLAC_stream_decoder_get_state", referenced from:
_main in main.o
"FLAC_stream_decoder_new", referenced from:
_main in main.o
"FLAC_StreamDecoderStateString", referenced from:
_main in main.o
"FLAC_StreamDecoderErrorStatusString", referenced from:
error_callback(FLAC__StreamDecoder const*,
FLAC__StreamDecoderErrorStatus, void*)in main.o
"FLAC_stream_decoder_init_file", referenced from:
_main in main.o
"FLAC_StreamDecoderInitStatusString", referenced from:
_main in main.o
"FLAC_stream_decoder_set_md5_checking", referenced from:
_main in main.o
"FLAC_stream_decoder_process_until_end_of_stream", referenced from:
_main in main.o
"FLAC_stream_decoder_delete", referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
From what i can understand is either: the linker is not seeing the libs (because it is seeing the headers) or the libFLAC was not compiled correctly. I'll be thankful if anyone will point me to possible solutions given these errors.
I was doing the linking incorrectly. Linking needs to be done according to this stackoverflow post Adding static library inside Xcode C++ project (How to add static libraries inside a C++ project with Xcode) but i was adding the linking directory under the Project Setting where i was adding my headers path, thus it was not working.
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
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.
So I'm trying to build a program using OpenGL and GLFW. The only errors I'm getting are:
Undefined symbols for architecture x86_64:
"_glewInit", referenced from:
_main in main.o
"_glfwCreateWindow", referenced from:
_main in main.o
"_glfwGetKey", referenced from:
_main in main.o
"_glfwInit", referenced from:
_main in main.o
"_glfwMakeContextCurrent", referenced from:
_main in main.o
"_glfwPollEvents", referenced from:
_main in main.o
"_glfwSetInputMode", referenced from:
_main in main.o
"_glfwSwapBuffers", referenced from:
_main in main.o
"_glfwTerminate", referenced from:
_main in main.o
"_glfwWindowHint", referenced from:
_main in main.o
"_glfwWindowShouldClose", 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)
So obviously this is a linking error. After doing some research, I think I found my error. It seems like I need to add the GLFW library (libglfw.dylib) and the Cocoa and OpenGL libraries. My problem is that I can't find libglfw.dylib - or anything glfw for that matter - under the "Link Binary With Libraries" section. I found OpenGL.framework and Cocoa.framework, but I can't find the glfw one. I tried going through the whole cmake process (cmake > make > sudo make install) for glfw but it didn't show up. I then tried installing using brew and that didn't work either. I can't figure out why I can't find this file. Any ideas? This is my first time doing anything with GLFW and one of my first projects doing any coding on OSX. If I'm forgetting any information you need to help let me know and I'll get it to you all as fast as I can.
First of all, using GLEW on OS X is 100% pointless (OpenGL extensions are all handled statically at link-time on this platform). You should add some code to your project that does something along the lines of:
#ifndef __APPLE__
// GLEW-specific code here
#endif
Also, .dylib is for dynamically linking - there's not much point in doing that on OS X. GLFW is not distributed in the form of a Framework, you'll have to compile it yourself. You can still use a dynamic linking version of GLFW if you wish, but you'd wind up having to package the library in your .app bundle. I would advise you just use the static version and avoid all of that.
Have you reviewed the OS X section of the GLFW compilation instructions?
I'm trying to write some C++ functions that can be run from Lua. However, when I try to import the header files, I get the following error:
Undefined symbols for architecture x86_64:
"_luaL_loadfilex", referenced from:
_main in main.o
"_luaL_newstate", referenced from:
_main in main.o
"_luaL_openlibs", referenced from:
_main in main.o
"_lua_close", referenced from:
_main in main.o
"_lua_pcallk", referenced from:
_main in main.o
"_lua_pushcclosure", referenced from:
_main in main.o
"_lua_setglobal", 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)
I've already added the file path to the Header Search Paths option in the Build Settings.
Here is the import code:
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
What am I doing wrong?
For a first working version, get the library here, extract the header files and the .a file into the same directory as the project file which has the code you posted in your question, then try to compile and link normally.
You may keep the references locally as in your question:
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
Later you refine your environment if that is needed.
The error you are getting is a link error not a compile error. The linker (called "ld") is complaining that it can't resolve symbols related to Lua. Make sure you have -llua52 in your link command so your library links to the Lua shared library (might be -llua or -llua5.2 on your system), and tell the linker where to find that lib via -Lpath/to/Lua/lib/folder.
I am building a Windows based project on my Mac. I have fixed a lot of the errors but when I go to compile it gives the following error:
Undefined symbols for architecture x86_64:
"Timer::reset()", referenced from:
Timer::Timer() in main.o
"Log::Log()", referenced from:
__static_initialization_and_destruction_0(int, int)in main.o
"Log::~Log()", referenced from:
___tcf_1 in main.o
"Render::initSDL(int, int, int)", referenced from:
init() in main.o
"Log::writeError(char*, ...)", referenced from:
init() in main.o
_SDL_main in main.o
"EntityManager::init(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)", referenced from:
init() in main.o
"EntityManager::loadAssets()", referenced from:
init() in main.o
"Level::getBlockCount()", referenced from:
EntityManager::getBlockCount() in main.o
"Level::getBombCount()", referenced from:
EntityManager::getBombCount() in main.o
"Level::getItemCount()", referenced from:
EntityManager::getItemCount() in main.o
"Render::renderElement(int, int, SDL_Surface*, SDL_Rect*)", referenced from:
renderScene() in main.o
"EntityManager::getElement(int, ElementType)", referenced from:
renderScene() in main.o
"Render::finishRender()", referenced from:
renderScene() in main.o
"EntityManager::update()", referenced from:
_SDL_main in main.o
"EntityManager::interpolate(double)", referenced from:
_SDL_main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I am curious as to why it only referenced a few functions? Do these functions contain non Mac compatible contents?
For example:
int Level::getItemCount()
{
return itemVec.size();
}
itemVec is a vector, just to be clear.
Thanks
If you run into linker errors, it means that the compiler could find the declaration but the linker couldn't find the definition
I suppose you already know but just in case :
For a method, the declaration is only it's signature
eg :
class foo
{
public:
void bar();
}
That is the declaration of the method "void Foo::bar()", and it goes into a header file (.h, .hpp, ...)
Now the definition of this method contains the body as well. It must match the declaration. Same example :
void Foo::bar()
{
std::cout << "Hello, world !" << std::endl;
}
That is the definition of the method "void Foo::bar()", and it (generally) goes into a source file (.cpp,.cxx, ...)
In your case, the compiler finds the delcaration but the linker doesn't find the definition. You have therefore to find where Timer::reset() is defined and check that this place is available for the linker.
The most typical reason for that would be that Timer::reset() is defined in a cpp file and that file isn't included in your xcode project (Don't worry, that happens all the time if you don't have a good build configuration tool such as Premake, Cmake, or whatever ...)
In that case the symbol will be declared because you have somewhere, in your code #include "timer.h" or something similar, but not defined because the matching cpp isn't included in your project. It (probably) exists on your hard drive but it's not referenced in your project.
To solve this :
Look up where Timer::reset is defined
If it's not defined anywherem then you just found your problem. It has to be defined if it's called
If it's defined, then check that the cpp is included in your project, in the same module as main.cpp
You mention that it happens only for specific functions. I might add that if a function is never called you won't get the error. Do you have this error message only with the functions which are actually called in main.cpp ?
For more details :
As far as I know (I might be wrong, because that's not a situation I normally run into) the compiler processes one file at a time and it's perfectly legal to have something declared but not defined (after all it could be defined in another file) at the compiling stage
The linker puts all the files togetherm so if a symbol is used (called, in your case) and it isn't defined, he is definitely going to complain.
HTH
Looks like you're not linking with the SDL framework or library (however it comes packaged).
In Xcode, click on your project (top of the files tree view), then your Target. Then click the Summary tab. That's where you'd add the SDL framework.
(If it comes as a .lib, you need to add an extra flag to the linker, such as "-lsdl").
Linking with SDL should take care of your unresolved externals.