I would like to develope an application using C++ and OpenGL for Windows 64bit.
I am using the following Compiler x86_64-w64-mingw32-g++.
The following code snippet (Test.cpp) is sufficient to trigger the error I get:
#include <GL/gl.h>
int main(int argn, char **argv) {
glClear(GL_COLOR_BUFFER_BIT);
}
(I know this code is meaningless, but it is sufficient to trigger the error during linking.)
I use the following Makefile:
Test:
g++ -lopengl32 -o Test Test.cpp
This yields the following error:
undefined reference to `__imp_glClear'
I have no clue what I am missing, and would be very thankfull for any advice.
For me the g++ main.cpp -o run.exe -lopengl32 seems to work just fine, so you most likely wont need -Wl,--enable-stdcall-fixup to compile it.
Related
I am attempting to make a testing application using libsodium, however I am getting the error:
main.cpp:6: undefined reference to `sodium_init'
I ran the following commands to install in as the root user.
$ ./configure
$ make && make check
$ make install
This the code that is having the issue.
#include <stdio.h>
#include <sodium.h>
int main(int argc, char **argv)
{
if (sodium_init() == -1)
{
return 1;
}
printf("libsodium had no issues!\n");
return 0;
}
I am using CodeLite as my IDE, and my C++ compiler options are the following:
-g;-O0;-Wall;-lsodium
The options were default and I added -lsodium to the list.
Attempting to compile main.cpp directly from the terminal with the following command g++ -lsodium main.cpp throws the same error.
Could someone please help me with my issue.
Libraries for linking are searched in order, so you need to place the libraries after your local translation units:
g++ main.cpp -lsodium
In your IDE, make sure you add -lsodium as a linker argument.
I'm experiencing a bit of strange behaviour when I try to compile any program that uses multithreading in CodeLite.
I get the error:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not premitted.
after some quick googling I found out I had to add "-pthread" to the compiler options.
Note: that CodeLite puts -l in front of libraries, so it does use -lpthread
After I clean, and rebuild the project, I still get the error though. As far as I can tell the build log looks fine?
The truly frustrating part comes about when I compile it manually via the command line, It works just fine.
I've searched, but none of the solutions seem to work for me? perhaps I've missed a step somewhere?
here's my test code.
I should also note I'm using Ubuntu14.04, and CodeLite 9.1.0
#include <iostream>
#include <string>
#include <thread>
void test()
{
std::cout << " Look it works! \n";
}
void int main(int argc, char** argv)
{
std::thread thrd_1 = std::thread(test);
thrd_1.join();
return 0;
}
Any help would be greatly appreciated!
You are passing -pthread in the compiler options. You need to pass it
in the linker options, and in the linker options you do not need
to specify pthread as a library. The -pthread option means
do whatever it is that links the posix threads library on this platform.
$ g++ -c -O0 -std=c++11 -o main.o main.cpp
$ g++ -o threadtest -pthread main.o
$ ./threadtest
Look it works!
I wanted to start learning to program with SDL. So I download x86 for windows,
put all the lib and the include in MinGW. But when I compile it doesn't know the SDL functions exist.
# define SDL_MAIN_HANDLED // somehow it want it to not define its own main
#include <iostream>
#include <sdl2/SDL.h>
using namespace std;
int main( int argc, char* argv[] ) {
SDL_SetMainReady(); // just for check
return 0;
}
I read that the linking need to be in specific order (mingw32, SDL2main and then libSDL2), But I think Eclipse run a wrong compiling command.
The eclipse command:
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\fire.o" "..\\src\\fire.cpp"
g++ -o fire.exe "src\\fire.o" -lmingw32 -lSDL2main -llibSDL2
src\fire.o: In function `main':
C:\Or\C++\Projects\fire\Debug/../src/fire.cpp:16: undefined reference to `SDL_SetMainReady'
collect2.exe: error: ld returned 1 exit status
Do you think I miss something?
I think you need to change -llibSDL2 to -lSDL2.
Ok I solve it. I'm not sure if the problem was lack of support on 32 bit or the fact that minGW and SDL were from different compilers that probably didn't match..
But what I did is to delete minGW from my pc and download WinBuild. WinBuild its a download manager that offer a lot of libs and tools, include minGW64 bit and SDL.
The advantage is that they were all compile from the same compiler with the same configurations.
after that i change the path to minGW in to the new 64 bit path inside WinBuild folder, add g++ from Winbuild the to the path as well and restart.
Then, adding and linking work without any problem!
I still need to put # define SDL_MAIN_HANDLED on the start to make it work, but its work!
As of late I have been getting the following error whenever I try to compile any program that uses the open cv libraries, I use g++ to compile:
g++ Example.cpp -o Ex `pkg-config opencv --cflags --libs`
No matter the content of the file (I have checked with programs that worked a couple of weeks ago) I always get the following error:
/usr/lib64/libX11.so.6: undefined reference to `xcb_poll_for_reply64'
/usr/lib64/libX11.so.6: undefined reference to `xcb_wait_for_reply64'
Do you have any idea of what might be the cause? (and how to fix it)
An example program that fails to compile:
#include "path/opencv2/highgui/highgui.hpp"
#include "path/opencv/highgui.h"
using namespace cv;
int main (int argc, char * argv[])
{
Mat image = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE) ;
return 0;
}
Add -lxcb to your command line (this will instruct the linker linking w/ the xcb library). Please make sure the 64b version of xcb is in the linker path (you can always put it explicitly via the -L switch)
The error was caused by some changes done to the libX11.so.6, talked with the FE machines support and they fixed it.
i'm trying to get into opengl programming, but fail to compile my first very very simple program. the linking process fails every time. i found this answer on stackoverflow, and have had all packages installed and told g++ which libraries to link against.
here's my sample program:
#include <GL/glut.h>
#include <GL/gl.h>
int main(int argc, char **argv) {
glutInit(&argc, argv);
return 0;
}
compiling results in the following error from the linker:
$ g++ -Wall -lglut -lGL -lGLU opengl.cpp
/tmp/cc1UAFPU.o: In function `main':
opengl.cpp:(.text+0x3b): undefined reference to `glutInit'
collect2: ld returned 1 exit status
anybody got any idea on this issue? there must be something which i am missing, but i just cannot see what. any hints to resolve this issue are highly appreciated!
might be order - either reorder libs, or put them after opengl.cpp