Compile g++ on XCode 5? - c++

I'm starting with OpenGL in c++, and I included GLUT and OpenGL frameworks on my project on XCode. When I try to compile and run my program as if it was a simple c++ program it gives me this error:
Undefined symbols for architecture x86_64:
"_glBegin", referenced from:
display() in main.o
"_glClear", referenced from:
display() in main.o
"_glClearColor", referenced from:
etc.
Using a simple c++ program, I don't get any of this errors. I searched the web and I found that I need to compile with g++ (specific for c++ lenguage), but I don't know how to do it. Any help?

You need to add -framework OpenGL to your compiler settings.

Related

Problems compiling windows c++ project on g++ 5 [duplicate]

This question already has answers here:
Using G++ to compile multiple .cpp and .h files
(13 answers)
Closed 7 years ago.
I have trouble with my C++ project which I created and compiled successfully within Visual Studio 2013 on a Windows machine. Currently I'm migrating the source to Unix platforms (my issue had been confirmed on Mac and CentOs). My project depends on the OpenMP (multithread support) library. Hence Apples LLVM compiler (version 6.0) does not support OpenMp sufficiently I decided to compile my project using g++-5.
After handling some syntax errors when moving from windows compiler to GNU's gcc/g++ (Homebrew gcc 5.2.0) I'm experiencing the following issue in the linking process:
The linker can not find symbols for my architecture and lists nearly every class/object which is created and included by me - what's curious, it does not list every of my classes/object.
I'm compiling with this command:
g++-5 myProject.cpp -o myProject -fopenmp -std=c++11 -L/usr/local/lib -I/usr/local/Cellar/libiomp/20150701/include/libiomp -Wall
Am I missing something stupid in my compiler call? Whats the reason for my linker issues?
As mentioned above, the same issue occurs on Mac and CentOs too.
EDIT (according to some comments):
According to this question I've activated all warning flags and the compiler is definitely happy with my code. But the linker is saying the following:
Undefined symbols for architecture x86_64:
"FileHelper::createFileName[abi:cxx11](char const*, char const*)", referenced from:
_main in ccZAvFqT.o
"Statistics::writeStats(char const*)", referenced from:
_main in ccZAvFqT.o
"Statistics::newSimulationRun()", referenced from:
_main in ccZAvFqT.o
"Statistics::newSimulationIteration()", referenced from:
_main in ccZAvFqT.o
"Statistics::Instance()", referenced from:
_main in ccZAvFqT.o
"Statistics::writeAvg()", referenced from:
_main in ccZAvFqT.o
"Statistics::~Statistics()", referenced from:
_main in ccZAvFqT.o
"GraphHelper::Graph::writeGraph(std::vector<IPeer*, std::allocator<IPeer*> >*, std::vector<Connection*, std::allocator<Connection*> >*)", referenced from:
[...] and so on and so on...
When you are compiling from command line, you need to make sure you include all object files (.o) when you link the executable.
Obviously, it is hard to control this manually, this is why people invented various sorts of Makefiles to do this for them. You can research this topic. To help your immediate problem, just make sure you have all your cpp files listed in your command line for compilation. Something like
g++ myProject.cpp Statistics.cpp ... <flags> -o <executable>

Linking OpenCL libraries while compiling C++ code with icpc

I am trying to compile a C++ program (that uses OpenCL functions) using Intel ICPC compiler: icpc mycode.cpp. I am getting the following error:
Undefined symbols for architecture x86_64:
"_clBuildProgram", referenced from:
_main in icpc4lnp65.o
..
..
"_clSetKernelArg", referenced from:
_main in icpc4lnp65.o
ld: symbol(s) not found for architecture x86_64
For g++ I saw that -framework OpenCL argument does the job of linking OpenCL libraries, but I am unable to figure out how to do the linking of OpenCL libraries using ICPC and there is not much documentation on using ICPC with OpenCL.

OSX Disk Arbitration linker errors

Trying to compile my C++ application using clang which works but I get the following linker error:
Undefined symbols for architecture x86_64:
"_DADiskCopyDescription", referenced from:
Security::getHddID() in Security.cpp.o
"_DADiskCreateFromBSDName", referenced from:
Security::getHddID() in Security.cpp.o
"_DASessionCreate", referenced from:
Security::getHddID() in Security.cpp.o
ld: symbol(s) not found for architecture x86_64
I've checked the official documentation for Disk Arbitration on the Apple website but that's awful, since it doesn't even tell you which library file to include, let alone what to link to.
I'm using CMake to set up my build chain.
You need to use -framework DiskArbitration in your linker arguments.

Problems with SDL image

I'm running on a mac OS 10.8.2 and compiling my program with the following command;
g++ main.cpp `sdl-config --cflags --libs` -o whateverfilename
I can compile SDL programs just fine but as soon as I try to use the SDL image library, things go wrong - I get the following errors:
Undefined symbols for architecture x86_64:
"_IMG_Init", referenced from:
_SDL_main in cco8lzYA.o
"_IMG_Load_RW", referenced from:
_SDL_main in cco8lzYA.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I'm guessing the linker is missing a search path or something. I've been trying to look up and edit the linker search paths but can't seem to manage even that so if someone could tell me how to do that or what other problems I might be causing I'd appreciate it :)
I think you need to add the lSDL_Image compiler flag, I'm very much a noob when it comes to C++ and SDL, it was ages since I've done anything with it.
I also very much recommend LazyFoo's tutorials

Link with Cocoa Framework from C++ and Objective-C++

I'm trying to use a Cocoa Framework (MultitouchSupport, to be specific) from within a basic Objective-C++ file, but I keep getting undefined symbol errors, as if g++ is supposed to have different linker flags than gcc.
My ultimate goal is to integrate a C++ networking library with some basic Objective-C code I got from here: http://steike.com/code/multitouch/.
When I run this to compile the original code, it works fine:
gcc -F/System/Library/PrivateFrameworks -framework MultitouchSupport test.m -o test -std=c99
But when I rename the file to test.mm, so that it can later include and reference C++ files, the following doesn't work:
g++ -F/System/Library/PrivateFrameworks -framework MultitouchSupport test.mm -o test
And gives me these errors:
Undefined symbols for architecture x86_64:
"MTDeviceCreateDefault()", referenced from:
_main in ccq0vzuM.o
"MTRegisterContactFrameCallback(void*, int (*)(int, Finger*, int, double, int))", referenced from:
_main in ccq0vzuM.o
"MTDeviceStart(void*, int)", referenced from:
_main in ccq0vzuM.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [testpp] Error 1
What do I need to do in order for this Objective-C++ file to see the Framework I'm looking for so I can use C++ with it?
Thanks!
In the header that declares those three functions, is there an extern "C" block that wraps them? Something like this?
#ifdef __cplusplus
extern "C" {
#endif
// function declarations here
#ifdef __cplusplus
}
#endif
If not: You could add one to the header file, or add a similar wrapper around your #import of that header file.