Can't find file executable in your configured search path for INTEL C++ compiler (Linux)

感情迁移 提交于 2019-12-08 12:38:45

问题


I want to debug my c++ code using code::blocks. I open a new project and paste my code. But there is above error. To be honest, I'm not sure what is my compiler! when I want to run my code, I write:

g++ -std=gnu++11 mycodename.cpp

in the terminal. How can I remove above error in Linux? A step by step answer is highly appreciated. I change the compiler from setting...compiler to gnu gcc but the error is about intel compiler!


回答1:


I want to debug my c++ code using code::blocks.

Don't, because you can't.

Code::Blocks is just an IDE, that is it is some source code editor capable to run compilers and debuggers. So Code::Blocks is not a compiler and is not a debugger (but it could run them).

I won't explain how you might use Code::Blocks. It has some documentation and some forum. I will rather try to explain how you should debug your C++ code.

compilation with g++

First, you compile with GCC (it a compiler, more precisely the GNU Compiler Collection; you'll use it with g++ program to compile C++ code, with gcc to compile C code, etc....). Read the chapter about Invoking GCC.

To compile a simple C++ program made of a single C++ translation unit (a C++ file yoursourcecode.cpp including some headers) into an executable yourprog use:

 g++  -std=gnu++11 -Wall -Wextra -g yoursourcecode.cpp -o yourprog

Notice that:

  • order of program arguments to g++ are important.

  • -std=gnu++11 defines your C++ dialect

  • -Wall -Wextra asks for all warnings and some extra of them. You really want warnings. You then need to improve your source code to get no warnings at all and repeat the compilation.

  • -g ask for debug info (in DWARF format). You want to be able to debug.

  • -o yourprog asks the compiler to generate as output the yourprog ELF executable

BTW, you cannot use Code::Blocks to compile your code. You could configure it to run the above command to compile it.

If your program is made of several C++ source files (and several translation unit) you need to compile every translation unit into an object file, and then to link these to make your executable. So with two source files yourfirstsource.cpp and yoursecondsource.cpp you need to run:

  • g++ -Wall -Wextra -g -c yourfirstsource.cpp -o yourfirstsource.o to compile the first yourfirstsource.cpp into the yourfirstsource.o object file.
  • g++ -Wall -Wextra -g -c yoursecondsource.cpp -o yoursecondsource.o to compile the second translation unit.
  • g++ yourfirstsource.o yoursecondsource.o -o yourprog to link both object files into an executable. You might link libraries with -Ldir and -llibname arguments (order is important, from higher level to lowel level libraries)

In practice, if you have several C++ files, you'll better use some build automation tool, like GNU make or ninja. That tool will run compilations and link commands like above. You should be able to compile (and link) on the command line.

debugging with gdb

Once you have an executable with debug info, you can use the gdb debugger. Read the Debugging with GDB documentation. I strongly recommend using gdb in a terminal. Start it with gdb ./yourprog (or gdb -tui ./yourprog if you want a terminal interface), then you get a (gdb) prompt and you can type debugger commands. The most useful ones are run (or r), break (or b), list (or l), print (or p), backtrace (or bt).

If you want to run your program directly, type its file path, e.g. ./yourprog in a command (i.e. some terminal). Be aware of globbing.

For benchmarking purposes, it is better to ask your g++ compiler to optimize with -O1 or -O2 etc.

but what about Code::Blocks

That tool is an editor, also able to run the g++ compilation and gdb debugging commands above. But you really need to become familar with these g++ and gdb tools on the command line. Once you can do that, dive into the Code::Blocks documentation to understand how to configure your source code editor (BTW my preference is emacs).

Code::Blocks is not able to compile your code or debug your program. It is just running external programs (such as the g++ compiler or the gdb debugger), but you should first learn to use g++ and gdb by yourself (outside of Code::Blocks or any other source code editor).


BTW, Intel makes a proprietary C++ compiler (I heard it is called icc, and you might need to pay for it). And there is also Clang/LLVM, which is (open source or) free software (like GCC is, but with a different license). Its clang++ program accepts arguments similar to those for g++. In many cases you could simply replace g++ by clang++ to use that Clang compiler.

Be also aware of the $PATH variable. You'll need to configure your shell (perhaps your ~/.bashrc) to change it.

I strongly recommend to learn how to use some version control system tool, like git (which has good videos and documentation and is very powerful).



来源:https://stackoverflow.com/questions/47081939/cant-find-file-executable-in-your-configured-search-path-for-intel-c-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!