opening an exe file in c++ form - c++

i am implementing an installtion program for my program , i am using c++, QT in debug mode , everything went well till the final stage (run the program after installation)
i tried these two ways for opening the exe file:
QString program= "example.exe";
method 1:
QDesktopServices::openUrl(QUrl("file:///"+program,QUrl::TolerantMode));
method 2:
QProcess::startDetached(program);
but it gives me that error message.

Possible some of application components not founded by executable file. For simple case QProcess::setWorkingDirectory( /* executable directory */ ) can help.
In bad case check environment variables of process in your run. You can loss paths to required libraries.

Related

Xml parsing exception on relative path with Eclipse gdb DSF debug

I'm using Eclipse Mars, with gdb 7.2.
While trying to debug a C++ application in Eclipse gdb DSF, I'm getting a parse exception. But I don't get the parse exception when I run the same program with gdb outside of Eclipse.
The exception states: "Fatal error during XML Parsing: unable to open primary document entity /path/to/file.xml"
But the actual path in xml is a relative path: "../../../../path/to/file.xml".
The C++ application is reading in the XML and trying to open this file.
It's as if the ../..'s are just getting chopped off, and that's why the error states essentially "I don't know about a /path/to/file.xml"
I imagine that something is wrong with my gdb setup in Eclipse, but I'm not sure what. I've tried many different things, none of which seem to work.
I imagine that this has something to do with relative paths not being recognized by gdb, or the working path being different in Eclipse vs gdb.
Does anyone have an idea what is wrong?
You need to make sure the Working Directory matches the location of the executable in the File System.
https://sourceware.org/gdb/onlinedocs/gdb/Working-Directory.html
Actually, this was a simple issue: It turns out that my Working Directory(in Debug Configurations under the Arguments tab) had to be set to the full path of the location of my executable.
I also had to set the path of my executable to the full File System path of the executable.
It works as expected now.

Running exe code from Matlab. The exact same instruction that works in cmd (dos) fails from Matlab

This is driving me crazy, I must admit. After finally being able to successfully compile two functions I need to process voice files, from C/C++ code that I downloaded from a trustworthy online repository (code that had been thoroughly tested in Linux), I am now struggling to launch those files from Matlab...
When I type the following command in cmd (dos)
Analysis b2.wav config_default
it works, no problem (see here Works).
Then, I build the exact same command into a string and feed it to the "system" Matlab function. Then the code crashes... (see here Fails) I've tried with full paths (c:\b2.wav, etc) but still does not work...
Any ideas as to why this might be happening?
Your image shows that the program Analysis stopped unexpectedly.
It might be a lot of reasons why, so let's go step by step:
1) Try executing Analysis from Terminal and passing wrong parameters (a file that doesn't exist, only one param (missing the config_defalut), no parameters at all, three parameters, etc...)
Can you make the program crash from terminal by passing wrong params?
2) Try creating the command first, checking that it's correct (\b is actually \b instead of a string modifier)
command_to_be_run = 'C:\Analysis C:\b2.wav C:\config_default'
disp(command_to_be_run) % is it showing exacly what you want?
system(command_to_be_run); % if so, run it.
3) Try creating a dummy executable dummy.exe in C that accepts two parameters and prints the received parameters (keep it super simple, just printing). Call it from Terminal. Does it work? Call it from Matlba. Does it Work?
With this 3 tests you can considerably narrow down where your error comes from.
By the way, is "config_default" a file or just a string that tells analysis how to behave? In some examples you treat it as a file, in others as a parameter without path.
Based on what's been tried so far and the outputs, here's my theory:
Premise: Analysis.exe came from code that's well tested in Linux. It works in Windows command line when run from the same directory where both it and the target file reside. But it stops working from Matlab console.
Assertion 1: Matlab console does not operate within the context of the directory where the binary is but rather within the Matlab directory. As such, Analysis.exe will try to find the target from the Matlab directory.
Validation for Assertion 1: Try putting the binary and the target wav in the Matlab directory. Then run system with the binary and target specified just by name (no path).
Assertion 2: If the file's full path is specified to address this issue, it still doesn't work. This may be because the code assumed a Linux file system where the delimiter is "/" rather than "\".
Validation for Assertion 2: Run with paths specified from the command line while in a diferent directory to see if it fails or not.
Possible Solution 1: Add the directory where both Analysis.exe and the target are into the Matlab path: (1) On the Home tab, in the Environment section, click Set Path. Add the path there. (2) addpath (folderName1,...,folderNameN) adds the specified folders to the top of the search path for the current MATLAB session. -> Then run the system command without the full paths.
Possible Solution 2: Add the directory where both Analysis.exe and the target are into the Windows environment path. Then run the system command without the full paths.
EDIT: Possible hackish solution - Create a batch file where: (1) you would cd to the directory where Analysis.exe and the target wav are; and (2) do a Matlab system call to the batch file.
EDIT 2: Possible experiment to validate assertion 2.

Executable error : Can't start program

After finishing my C++ program (on windows os using codeblocks)(using libcurl) when i try to launch the program from the executable it displays an error saying that i can't start the program because libcurldll is missing,reinstall program then retry. I don't think any line of code is needed here,it's just a configuration and logics problem,any ideas,would be great !
Please note that,running it from the codeblocks's console works fine.
Common issue with DLLs or SOs is that the executable needs to know where they are.
A common solution is to place the DLL library in the same folder as the executable:
Find the libcurldll file.
Find the folder containing your executable.
Copy the libcurldll file into the folder containing your executable.

How to use Instruments Time Profiler with Executable

I'm trying to use Mac Instruments Time Profiler to optimize my code for building a MandelBox. I found how to make my executable my target process, but when the program runs, it gives me an error in the Console window saying it cannot find the .txt file associated with the program.
Do I need to tell the profiler where to look to find the file? The text file is already in the same directory as the executable. Any thoughts? Thanks.
This problem is not unique to Instruments. The same thing would presumably happen if your current working directory was something other than the location of your program. For example, if you were to do cd / ; /path/to/yourprogram.
You either need to make your program find its own location and then find its text file as a sibling in the containing directory or take the path of the text file as an argument. Or, you will always have to set the working directory to your program's location before invoking it.
That last approach is an immediate workaround for the problem with Instruments. On the panel where you choose the target executable, you can also configure various parameters, such as arguments, environment variables, and the working directory. Set the working directory to the directory that contains the text file and it should work.

Matlab will not run my C++ .exe file

I have program in C++ that runs great but it has different steps in it. It opens a file first then does some calculations based on the data it gets from the file. Now I'm trying to run it through matlab. I tried mex but it got too complicated because I have VS 2010 Express and MATLAB 2007b. And so mex can never find my c compiler.
I'm now trying to just run it straight from the C++ program executable file. Here's how I tried to do it:
system('C:\path\file.exe')
it would run but the command window freezes and I have to close Matlab every time to get back on track. Then I tried to double click on the executable file it self. It flashes but I can see it outputs something from my file "file could not be uploaded" which is generated by a part of my program if it cant find the file.
So then I realized it's probably because of that that caused it to not run and crash.
So I wrote a sample code to open the file first before the system command open the .exe file. I've done something like fopen('fname','r'), but nothing works. Please note that this file I'm trying to open is a .COF file.
I tried running the .exe file using debug and release modes but nothing happens. It gives no errors which means it sees the .exe file but the command line doesn't come up and matland command window freezes.
After running, it's supposed to prompt the user at the command line then take input arguments and output something...
Please help....
I am guessing that your .COF file is in a different path than what's accessible by your binary. If you can recompile, try an absolute path name, and test it first without MATLAB.
There are more thorough ways to solve this, like passing the filename to your binary as a command line argument, or to read up what the rules are for the "current directory" when you use system, but perhaps you'd be happy with the quick solution.