C++ compile error. G++ gnu [duplicate] - c++

This question already has answers here:
Can I get Unix's pthread.h to compile in Windows?
(5 answers)
Closed 6 years ago.
Hi I am having some issues with my c++ program. I am using g++ gnu and it is on windows 10. here is the error that is showing up:
ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
please help because i can not work out what is going on.
Thanks,
Asher

That is a linker error. Not a compiler error.
It is complaining that it cannot find the pthread library in the library search path. Either it simply isn't there or you need to indicate where it is with the -L option. Or, in case pthread is not needed, remove the -lpthread option so you don't attempt to link to it.

Related

Compiling openGL with GLFW3 program in Ubuntu 15.10 [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I tried building GLFW3 under Ubuntu 15.10 using the tutorial here, and while that seems successful, I can't compile a sample program (provided by GLFW) using the command:
g++ test.cpp -lglfw3 -lGL
I get the following error.
/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
/usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I tried including a bunch of different files in the linker, but thes two I have now took away all the other errors except these. I also read that the DSO missing error might indicate the wrong order of linked files, but changing the order doesn't help here. Probably missing some include, but no idea which. If anyone can help, it'd be greatly appreciate. I'm quite new to Linux, so this is beyond my current skills.
You need to get the packages. Run in the right order.
pkg-config --static --libs x11 xrandr xi xxf86vm glew glfw3

compile C in CentOS face error: undefined reference to [duplicate]

This question already has an answer here:
Why am I getting a gcc "undefined reference" error trying to create shared objects?
(1 answer)
Closed 7 years ago.
I compiled C in CentOS and face this error:
cc -c -o obj/BT.o BT.c -I./include -I/usr/dialogic/inc
cc -o BT obj/BT.o obj/util.o -I./include -I/usr/dialogic/inc -L/usr /dialogic/lib
obj/BT.o: In function 'main':
BT.c:(.text+0x52): undefined reference to `gc_Start'
collect2: ld returned 1 exit status
make: *** [BT] Error 1
I already linked to library -L/usr /dialogic/lib but i don't know why it does not link when create binary file
Please, any one can suggest me something ?
check if you had saved your.c file and also check of spelling of the functions' definition and their calls .

Why this code doesn't build with clang, crashes with gcc, but runs fine with VC++? [duplicate]

This question already has answers here:
What are the correct link options to use std::thread in GCC under linux?
(5 answers)
Closed 8 years ago.
This code:
#include <iostream>
#include <future>
int main()
{
std::async([]{std::cout << "hello\n";}).get();
}
runs fine and prints hello with Visual C++ 2013, but throws an exception with gcc producing:
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
and doesn't even build with clang, producing this error message:
/usr/bin/ld: /tmp/source-83f28e.o: undefined reference to symbol 'pthread_setspecific##GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I used rexter to run the tests. Can you explain this behavior?
EDIT
With -pthread compiler option gcc version runs fine and clang version builds now and produces:
hello
exception_ptr not yet implemented
In order you add support for multithreading, you need to link against the pthread library. This is -pthread (available as a built-in flag) on both GCC and Clang. Alternatively, -lpthread may do the trick.

Undefined reference to PQfinish even though libraries etc. are included [duplicate]

This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 8 years ago.
I'm trying to compile a C++ application using libpq.
On my Debian it compiles fine with the following command:
g++ -I /usr/include/postgresql/ -L /usr/lib/postgresql/9.3/lib/ -lpq -o test test.cpp
On my Ubuntu I get the following error:
undefined reference to 'PQfinish'
I've included link to postgresql headers and libraries and used the -lpq. What am I missing?
Move -lpq to the end of the command line.
Linking is done in the order specified, and objects are only taken from libraries if they are needed to resolve symbols at that point. So each library has to come after any other object that needs it.

Trying to run OpenGL on Linux, have the necessary libraries but won't run? (C++) [duplicate]

This question already has answers here:
Linker error : undefined reference to symbol 'glOrtho'
(2 answers)
Closed 8 years ago.
I am new to Linux and am currently using Linux Mint. I followed the instructions on this page, however whenever I go to compile the example code (given on the web page), the build fails.
g++ ~/Desktop/test.cpp -lglut gives me the following:
/usr/bin/ld: /tmp/cc3aKYsD.o: undefined reference to symbol 'glOrtho'
/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Why does this keep occurring? I apologize for such a beginner question, but this is irritating.
You need to link with the OpenGL library as well:
g++ ~/Desktop/test.cpp -lglut -lGL