I have a hello world cpp file. If I compile it by c++ test.cpp -o test i get "test" file that is executable (-rwxr-xr-x) and if I execute it, it is executed and generates an expected result.
However, if I use ${CXX} -std=c++0x -I${INCLUDE_DIR1} -c test.cpp -o test -L{LIB_DIR1} -llib_name I also get the "test" file but in this case it is not executable. So, I cannot execute it. I tried to chmod +x, it gets permissions to be executed but if I try to execute it get an error message (cannot be executed).
What am I doing wrong and how it can be corrected?
-c tells the compiler to not generate an executable (it means "compile only"). It only creates an object file, that is suitable for being linked into an executable (possibly with other object files and libraries).
Remove the -c switch if you want an executable.
For more details on the complete compilation process, see: How does the compilation/linking process work?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With