File not found under debug in C/C++ only

in C/C++, fopen() returns file not found under debugger. when I run the test app in the putty terminal, there is no problem.
when running under debugger, the get current directory command, return /WhateverINamedMyAPP
instead of /home/Torizon/WhateverINamedMyAPP/bin

I also try using C# to open file under debugger and terminal, both have no problem.

I download the test data file by putting the file in the work directory.
…\appconfig_0\work\XXX

Apalis iMX8QM 4GB WB IT V1.1B
Ixora V1.2A
Torizon
VSCode 1.59

Greetings @swc,

I think I know what’s the issue here and it’s due to how the container filesystem works. What you might be misunderstanding is that the filesystem inside the container is mostly independent from the filesystem on the host.

For the sake of debugging the filesystem location /home/Torizon/WhateverINamedMyAPP is mounted in the the container at the location /WhateverINamedMyAPP. Since your C/C++ application lives inside the container, it can only see the container filesystem and not the host filesystem.

Meaning any file operations and such need to take this into account. Your command for getting the current directory is correct because /WhateverINamedMyAPP is what the location is inside the container /home/torizon exists outside of the container and thus can’t be seen by your application.

On the device you can use docker exec in order to get a shell into a container. This can be useful if you’re having trouble visualizing what the filesystem inside the container looks like.

Best Regards,
Jeremias

so how do I get a data file (that’s on my windows pc) into the container while I’m debugging?

I am NOT using full path to open the file.
I am just using current directory, so I expected both to work: fopen(“data.txt”, "r) even during debugging, but doesn’t. When I docker run the image, there is nothing in the /WhateverINamedMyAPP directory.
and of course, when I log in using putty, everything is /home/Torizon/WhateverINamedMyAPP and everything works.

You would need to define this in the project configuration. See this section here for the relevant configuration(s): C/C++ Development and Debugging on TorizonCore Using Visual Studio Code

Best Regards,
Jeremias

finally worked, the files were in “current dir”/bin directory. (although I tried that before, it wasn’t working, but now it is. must have did something wrong before)
and what also confuse me is that the container doesn’t have the executable, so I can see what’s going on and try running the container in the putty.
Do you know why that is? see image:

Hmm I’m not sure where you’re executable is. It’s suppose to be there in the container under the folder with your project name. I did a quick test and made a simple C/C++ project to show this:

apalis-imx6-05228985:~$ docker exec -it d bash
torizon@db2bc38b860e:/test$ ls
test

As you can see my executable is present (name of my project/application is “test”).

Best Regards,
Jeremias

that’s odd. I just try it to create a simple test app and the container doesn’t have exe in it.
I’m using early access version, could that be the problem?
are you using vscode? I am using vscode cmake template.
also in vscode cmake it should have a bin folder in your test app.
maybe this is a bug in the vscode’s extension?
I am vs 2019 generates different from vscode.
vs code puts the exe outside the container and vs 2019 does not (but I have not check if it where it have it inside the container)

I’m using VSCode with the early access version as well.

Also to clarify in my previous test the C/C++ executable was both inside and outside the container (located at /home/torizon/test/test). Also my test was with a simple single C/C++ file template. For cmake though it shouldn’t be much different.

Try doing a search both inside and outside the container for the executable name. I mean for debugging it must be executing from somewhere.

I tried the simple single c/c++ file template also, and still nothing inside the container.
only have the app folder
I search everywhere, nothing.
it only exist outside the container.
any idea?

My colleague also checked his docker images and same as me no executables in the images.

Oh wait I think there’s a misunderstanding here.

For the debug configuration the executable and any other relevant files are bind-mounted from the host /home/torizon/<application name> into the container. What you did earlier was just run the debug container with bash which doesn’t bind mount the files in the container.

You need to look at the container while it’s running as it was ran by the extension. Do not attempt to run the debug container manually as this really doesn’t make sense in context. What you should do is run deploy/debug from the extension. The extension will remotely run the container on the target device with certain flags and arguments.

Then if you want to a shell in the container you can then use docker exec to get inside the container while it’s already running.

If you build the release version of the container then the executable and all files will actually be built into the container image. For debugging purposes the files are outside of the container on the TorizonCore host and then bind-mounted into the container at run-time.

Best Regards,
Jeremias

Thanks the explanation. that works.
I thought about that this morning and try, but wasn’t working. must have done something wrong or use wrong command palette as I was using F5 to deploy after switch to release mode.
now it works by building release container and deploy release…