Code::Blocks Forums

User forums => Help => Topic started by: markpotts on November 11, 2020, 12:29:47 am

Title: 'No such file or directory' error running in terminal
Post by: markpotts on November 11, 2020, 12:29:47 am
Running under Linux (Ubuntu 20.04) I can build an application using Code::Blocks and run it from the IDE (in Debug or Release mode) without problem. However when I try to run the same executable under terminal I get a 'No such file or directory' error. This was not an issue with earlier Linux/Code::Blocks versions

If I build the same application using 'gcc' directly from the command line it build and runs correctly with no problem.

Any thoughts would be much appreciated.

Title: Re: 'No such file or directory' error running in terminal
Post by: oBFusCATed on November 11, 2020, 12:34:49 am
You have to give us more details... How are you running the executable? Does it depend on external libraries? Are they found?
Title: Re: 'No such file or directory' error running in terminal
Post by: markpotts on November 11, 2020, 12:45:23 am
The executable is stand-alone with no libraries. In terminal I simply type the path to the executable. This works if I compiled with gcc from the command line but gives the error if compiled with CB.
Title: Re: 'No such file or directory' error running in terminal
Post by: stahta01 on November 11, 2020, 03:20:02 am
Post the full build commands used; Both inside Code::Blocks and on the command line.

http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)

Tim S.
Title: Re: 'No such file or directory' error running in terminal
Post by: markpotts on November 11, 2020, 08:41:07 pm
Inside CB:
  Build->Rebuild
  Build->Run    [works correctly]
 
then in terminal:
  ~$ ./name    [fails 'No such file or directory']

Command Line:
 ~$ gcc name.cpp -lpthread -o name
 ~$ ./name   [works correctly]

I will review the suggested FAQ, thanks.
Title: Re: 'No such file or directory' error running in terminal
Post by: oBFusCATed on November 11, 2020, 09:05:35 pm
Why do you think cb is generating ./name and not ./debug/name or ./release/name?
If you inspect the build log or your project settings you'll see where the executable is generated.
Title: Re: 'No such file or directory' error running in terminal
Post by: markpotts on November 11, 2020, 10:04:05 pm
CB generate the executable in bin/Release (or bin/Debug). This is where it runs (correctly) from within the IDE. Running the same executable outside the IDE fails. Building via gcc from the command line generates an executable wherever specified (-o). This executable runs correctly.

Following is a log of the different behaviors:

in Code::Blocks
-------------- Clean: Release in Barcode (compiler: GNU GCC Compiler)---------------
Cleaned "Barcode - Release"
-------------- Build: Release in Barcode (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -O2  -c /home/user/Source/Barcode/Barcode.cpp -o obj/Release/Barcode.o
g++ -o bin/Release/Barcode obj/Release/Barcode.o -s -lpthread
Output file is bin/Release/Barcode with size 22.58 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
-------------- Run: Release in Barcode (compiler: GNU GCC Compiler)---------------
Checking for existence: /home/user/Source/Barcode/bin/Release/Barcode
Executing: xterm -T Barcode -e /app/bin/cb_console_runner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. /home/user/Source/Barcode/bin/Release/Barcode  (in /home/user/Source/Barcode/.)
this works ...
Barcode [Nov 11 2020, 11:58:37]

then in terminal
~/Source/Barcode$ ls bin/Release
Barcode
~/Source/Barcode$ bin/Release/Barcode
this fails ...
bash: bin/Release/Barcode: No such file or directory

recompile with gcc
~/Source/Barcode$ gcc Barcode.cpp -lpthread -o Barcode
~/Source/Barcode$ ./Barcode
this works ...
Barcode [Nov 11 2020, 12:13:24]

Title: Re: 'No such file or directory' error running in terminal
Post by: stahta01 on November 11, 2020, 10:55:08 pm
Please change the current directory to the folder with the executable in it.

This will then be a real comparison instead of one where your OS can be the cause of the problem; because what you posted says the OS is the reason it is failing.

Tim S.
 
Title: Re: 'No such file or directory' error running in terminal
Post by: markpotts on November 11, 2020, 11:40:47 pm
~/Source/Barcode/bin/Release$ ls -l
total 24
-rwxr-xr-x 1 user user 23120 Nov 11 11:58 Barcode
~/Source/Barcode/bin/Release$ ./Barcode
bash: ./Barcode: No such file or directory

This is under a new install of Ubuntu 20.04 with Code::Blocks 17.12. I have previously compiled a range of custom programs for an IoT product using earlier versions of Ubuntu/CB without any problem. I was recently forced to upgrade the Linux/CB versions due to hardware support issues which was when this issue emerged. If necessary I can recompile everything using gcc from the command line but I would prefer to build using the CB IDE.

I noticed that CB uses a complex command to execute the program but I am not sure what this implies:
Executing: xterm -T Barcode -e /app/bin/cb_console_runner LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. /home/user/Source/Barcode/bin/Release/Barcode  (in /home/user/Source/Barcode/.)
Title: Re: 'No such file or directory' error running in terminal
Post by: oBFusCATed on November 12, 2020, 12:53:58 am
This is really odd.

Are there any messages in dmesg for this event?
Do you have some protection system running (apparmor, selinux, etc)?
What happens if you use "file" or "objdump -d" on the file? ldd on the file?

Generally you want to pass -pthread to both compilation and linking, but I doubt this would change anything.
The execution in cb is complex, because it has to start a terminal, make sure it pauses after the executable ends and if there are libraries in non-default places they are found.
Generally the last thing surprises people the most, but you're not linking to any shared library. :shrug:
Title: Re: 'No such file or directory' error running in terminal
Post by: markpotts on November 12, 2020, 08:38:53 pm
There is nothing written to dmesg when the error occurs
apparmor is running by default but no effect if disabled

The file command output may contain a clue. The working version compiled from the command line is an "ELF 64-bit LSB shared object, not stripped". The CB compiled version that runs from the IDE but fails from the command line is an "ELF 64-bit LSB executable, stripped".

~/Source/Barcode$ file Barcode
Barcode: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=492d894beb613937df192d803629005eb8b17095, for GNU/Linux 3.2.0, not stripped

~/Source/Barcode/bin/Release$ file Barcode
Barcode: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=923304fc1cda1c3474db62bb3d70b5c230fed520, stripped
Title: Re: 'No such file or directory' error running in terminal
Post by: oBFusCATed on November 12, 2020, 11:50:21 pm
Stripping doesn't matter.
Either remove -g from the compiler or add -s to the linker and it will be the same, but it won't solve the problem.
What happens if you execute the same commands from the build log?
You should get the same effect.