I have a simple example to test my IDE, to get ready my C++ environment. I'm currently using Codeblocks 13.12 in Ubuntu 14.04.

When I build my program, the compiler executes the following code, and the program will throw an error when running.

g++-4.8 -Wall -fexceptions -O3 -pedantic-errors -std=c++11 -Wextra -Wall -pthread  -c /home/mikeldi/workspace/codeblocks/main.cpp -o obj/Debug/main.o
g++-4.8  -o bin/Debug/test obj/Debug/main.o   

ERROR:

terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)

In the other hand, if I execute the following line (note that I don't use -c before main.cpp) the program will execute without any problem.

g++-4.8 -Wall -fexceptions -O3 -pedantic-errors -std=c++11 -Wextra -Wall -pthread main.cpp  -o main

So, my question is: What does the -c do that makes the program not work? Is there any way of setting codeBlocks so it doesn't use -c?

Thanks in advance,

有帮助吗?

解决方案 2

As PeterT said in the comment, both the compiler and the linker need -pthread once that solved, the program worked fine:

g++-4.8 -Wall -fexceptions -O3 -pedantic-errors -std=c++11 -Wextra -Wall -pthread  -c /home/mikeldi/workspace/codeblocks/main.cpp -o obj/Debug/main.o
g++-4.8  -o bin/Debug/test obj/Debug/main.o -pthread

Thank you everybody.

其他提示

If your program throws an error at runtime, the problem is much more likely to be in your code than in the compiler switches you're using. With that said, there are much more significant differences between the two compiler invocations than -c. In particular, the differences are

-fexceptions -march=corei7  -g

If you add those compile switches to your command-line invocation, as with

g++-4.8 -fexceptions -march=corei7 -g -O3 -pedantic-errors -std=c++11
    -Wextra -Wall -pthread main.cpp -o main

you can recompile your code and see that it probably still crashes. Find out where by stepping through your code using the debugger of your choice, since the -g flag tells the compiler to include debugging information into the generated object file.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top