I'm trying to find an equivalent feature in Qt Creator that I currently know how to do in Visual Studio.
In Visual Studio I'm able to modify the PATH environment in the Property Pages-> Configuration Properties-> Debugging-> Environment and I can set something like:
PATH=%PATH%;%MYENVIRONMENTVAR%
Where MYENVIRONMENTVAR points to a directory (lets call it C:\MYIMPORTANTDLLS) containing dlls needed for my program to run.
I'm looking for the equivalent of this in Qt Creator. In Qt Creator I thought I would accomplish this in Projects-> Select the Run tab-> Expand the Build Environment Details and modify the Path there. But I can't append an environment variable to the end of the PATH in that location. Instead I have to append the path contained in my environment variable to the end of the entire PATH, which would look something like this: PATH=C:\path1;C:\path2;C:path3;...etc...;C:\MYIMPORTANTDLLS.
If any of you know how this is done in Qt Creator then I would appreciate your help.
There is a way to specify other dependencies of the project immediately in the project .pro file. Example from project file:
OTHER_FILES += ..\third-party\libxml2\bin64\libxml2.dll \
..\third-party\libiconv\bin64\libiconv.dll
You were so close with opening Projects-> Select the Run tab (or Build if you need to change the path for the build step) -> Expand the Build Environment Details and modify the Path there. Then edit the PATH variable to
$(PATH);C:\YourPathAddition
Related
I developed an application that depends on a DLL file. When I debug my application, the applicationwould complain that:
"This application has failed to start because xxx.dll was not found."
So I have to copy the DLL file into the same directory as my .vcproj file.
Is there a way to set the project to look for the DLL file in (preferably) some relative path or (not preferred) some absolute path?
Similar concept to how we set include and library path in the project settings.
I mean when I debug my application (hitting F5) the above error would pop up.
Go to project properties (Alt+F7)
Under Debugging, look to the right
There's an Environment field.
Add your relative path there (relative to vcproj folder) i.e. ..\some-framework\lib by appending PATH=%PATH%;$(ProjectDir)\some-framework\lib or prepending to the path PATH=C:\some-framework\lib;%PATH%
Hit F5 (debug) again and it should work.
Go through project properties -> Reference Paths
Then add folder with DLL's
The search path that the loader uses when you call LoadLibrary() can be altered by using the SetDllDirectory() function. So you could just call this and add the path to your dependency before you load it.
See also DLL Search Order.
Another possibility would be to set the Working Directory under the debugging options to be the directory that has that DLL.
Edit: I was going to mention using a batch file to start Visual Studio (and set the PATH variable in the batch file). So then did a bit of searching and see that this exact same question was asked not long ago in this post. The answer suggests the batch file option as well as project settings that apparently may do the job (I did not test it).
In your Project properties(Right click on project, click on property button) ▶ Configuration Properties ▶ Build Events ▶ Post Build Events ▶ Command Line.
Edit and add one instruction to command line.
for example copy botan.dll from source path to location where is being executed the program.
copy /Y "$(SolutionDir)ProjectDirs\x64\Botan\lib\botan.dll" "$(TargetDir)"
I had the same problem and my problem had nothing to do with paths. One of my dll-s was written in c++ and it turnes out that if your visual studio doesn't know how to open a dll file it will say that it did not find it. What i did was locate which dll it did not find, than searched for that dll in my directories and opened it in a separate visual studio window. When trying to navigate through Solution explorer of that project, visual studio said that it cannot show what is inside and that i need some extra extensions, so that it can open those files. Surely enough, after installing the recomended extension (in my case something to do with c++) the
"This application has failed to start because xxx.dll was not found."
error miraculously dissapeared.
I know this question had been answered years ago, but for those like me who needed to change where the debugger starts the application, change the command property under Project Properties -> Debugging.
I developed an application that depends on a DLL file. When I debug my application, the applicationwould complain that:
"This application has failed to start because xxx.dll was not found."
So I have to copy the DLL file into the same directory as my .vcproj file.
Is there a way to set the project to look for the DLL file in (preferably) some relative path or (not preferred) some absolute path?
Similar concept to how we set include and library path in the project settings.
I mean when I debug my application (hitting F5) the above error would pop up.
Go to project properties (Alt+F7)
Under Debugging, look to the right
There's an Environment field.
Add your relative path there (relative to vcproj folder) i.e. ..\some-framework\lib by appending PATH=%PATH%;$(ProjectDir)\some-framework\lib or prepending to the path PATH=C:\some-framework\lib;%PATH%
Hit F5 (debug) again and it should work.
Go through project properties -> Reference Paths
Then add folder with DLL's
The search path that the loader uses when you call LoadLibrary() can be altered by using the SetDllDirectory() function. So you could just call this and add the path to your dependency before you load it.
See also DLL Search Order.
Another possibility would be to set the Working Directory under the debugging options to be the directory that has that DLL.
Edit: I was going to mention using a batch file to start Visual Studio (and set the PATH variable in the batch file). So then did a bit of searching and see that this exact same question was asked not long ago in this post. The answer suggests the batch file option as well as project settings that apparently may do the job (I did not test it).
In your Project properties(Right click on project, click on property button) ▶ Configuration Properties ▶ Build Events ▶ Post Build Events ▶ Command Line.
Edit and add one instruction to command line.
for example copy botan.dll from source path to location where is being executed the program.
copy /Y "$(SolutionDir)ProjectDirs\x64\Botan\lib\botan.dll" "$(TargetDir)"
I had the same problem and my problem had nothing to do with paths. One of my dll-s was written in c++ and it turnes out that if your visual studio doesn't know how to open a dll file it will say that it did not find it. What i did was locate which dll it did not find, than searched for that dll in my directories and opened it in a separate visual studio window. When trying to navigate through Solution explorer of that project, visual studio said that it cannot show what is inside and that i need some extra extensions, so that it can open those files. Surely enough, after installing the recomended extension (in my case something to do with c++) the
"This application has failed to start because xxx.dll was not found."
error miraculously dissapeared.
I know this question had been answered years ago, but for those like me who needed to change where the debugger starts the application, change the command property under Project Properties -> Debugging.
Im using Codelite IDE and build test.exe gui application. When i started application i got error that some dlls missing. I found all that dll and put in folder where is test.exe, and all is working now. But with all that dlls there is mess in main folder.
How to move that dlls to sub directory so application still work, except i add that folder in PATH?
You need to change the PATH environment variable
To make it work in CodeLite, add line similar to this from: Settings->Environment variables
PATH=$PATH;C:\Path\To\My\Dll\Folder
Ofc, replace C:\Path\To\My\Dll\Folder to the actual path where you want your DLLs to be placed
Eran
Try this work-around:
Right click to your project - settings - general.
Change the "Executable to Run / Debug" to:
$(ProjectPath)/$(IntermediateDirectory)/$(ProjectName)
Change the "Working Directory" to:
$(ProjectPath)/YOUR DLL DIRECTORY
Hi I have a VS2010 projekt witch i moved from one machine to another. And on the new machine the QT installation is in a different place.
Now the projekt can´t find the QT headers and libs. When i look in the projekt properties I see that all QT path are set with the makro $(QTDIR) and this path is the path of the old machine.
Is there any way to change the value of the makro?
THX for help
There is such thing as User Macros in VS 2010. It can be defined in Property Sheets. To find it you should open View->Property Manager panel, and there you'll see your projects and configurations. It will look like this:
In my project, I have a foldernames property sheet, in QT the name might be different. So you should right-click the property sheet and you'll see User macros page under Common properties:
Check there for your QTDIR macro.
I believe QTDIR is system/user variables that you need to define on your Windows.
You can take a look at : http://support.microsoft.com/kb/310519 that explain how to set the value.
Or, you can take a look at: http://www.itechtalk.com/thread3595.html
Once you set the variable, you may need to restart visual studio
To check if the variable has been set, type the following in command prompt:
echo %QTDIR%
I would like to use Qt creator and Cmake together (please, don't ask me about my motivation, accept this as a given.)
I successfully set up Qt creator to use cmake "Cmake": see this, this and this documents regarding how I did that.
I successfully create hello world project, but I can't create files in project,
only add existing files to project tree and after that adding it to cmake list.
Standard operation of Qt creator "Add New..." doesn't work and I can't find why.
Is there anybody who uses Qt creator and "Cmake" together? Is the combination actually possible?
Note: I'm using Qt creator v2.4.1.
You can add files using glob expression in your CMakeLists.txt, like this:
file(GLOB SRC . *.cpp)
add_executable (your_exe_name ${SRC})
Cmake will pick your new cpp files next time you run it and QtCreator will show them in the project browser.
Update
This solution may be useful but as noted in comments - this is not a good practice. Every time somebody add new source file and commit changes, you need to rerun cmake to build all the sources. Usually I just touch one of the CMakeLists.txt files if my build is broken after I pool recent changes from repository. After that make will run cmake automatically and I didn't need to run it by hands. Despite of that I think that explicit source lists in CMakeLists.txt is a good thing, they called thing CMake Lists for a reason.
When you add new files in QtCreator using the "New File or Project..." dialog it only creates the files on disk, it doesn't automatically add the files to the CMakeLists.txt. You need to do this by hand by editing the CMakeLists.txt file.
The next time you build the project, CMake will be re-run, and QtCreator will pick up the new files and show them in the project browser.
I solve this problem that I added new files in standard way (CTRL+N), then added needed files in CMakeLists. After that, right click on project in project tree view and choose option Run CMake. After this, files showed in project list tree. Only build was not enough.
I tested here and happened the same behavior because those options you were asking were really disabled.
Use File -> "New File or Project..." or CTRL+N to add new files and after that add to CMakeLists.txt
I'm adding an updated answer for newer versions of QtCreator (4.x, I don't know precisely which release but at least from 4.7). In the Tools > Options... menu, choose the Build & Run section and then the CMake tab. You will see the Adding Files settings, and you can set it to Copy file paths :
This way, when you want to add a new file to your project, in the Project view, right click on the desired CMake Executable/Library's name and select Add New..., go through the Add dialog, and when you'll validate the dialog, QtCreator will open CMakeLists.txt in the Editor view. Finally, paste the content of the clipboard at the end of the corresponding source file list and save CMakeLists.txt. The CMake project will be parsed, and your new file will show up in the Project view.