My folder hierarchy looks like this:
bin -> data -> blurf.xml
lib -> blurb.lib
src -> blah.cpp
msvc -> project_name -> project_name.sln ...
....
Here is my issue. This project needs to run on Linux and Windows
So I need that when I build it in MSVC, the exe ends up in ../../bin
This is because my application has a data folder and the application expects to find in the root where the exe is.
Is there a way that when I run a build, it thinks it is (or is) in the ../../bin directory so it accesses the data folder?
If not, is there some other way I can have it know where its data is when I run from MSVC?
Go to project properties, Debugging sheet and set 'Working directory' accordingly
Related
https://github.com/fmtlib/fmt
I'm having trouble using c++ library on ubuntu eclipse. I downloaded the fmt library from github. I followed the steps as described in the documentation section Building the Library. In fmt folder;
mkdir build # Create a directory to hold the build output.
cd build
cmake .. # Generate native build scripts.
After running the commands, makefiles are created in the build array.
To install the library I ran following command.
sudo make install
After the installation, the necessary files were copied to the /usr/local/ directory. I copied the header files and compiled libfmt.a file to my project directory.
My project hierarchy;
fmtTestProject
|--Debug
|--src
|--fmtTest.cpp
|--include
|--args.h
|--chrono.h
|--color.h
|--compile.h
|--core.h
|--format.h
|--format-inl.h
|--os.h
|--ostream.h
|--printf.h
|--ranges.h
|--std.h
|--xchar.h
|--lib
|--libfmt.a
I defined the include files to the eclipse project.
fmtTest -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler -> Includes -> Include paths -> "${workspace_loc:/${ProjName}/include}"
fmtTest -> Properties -> C/C++ Build -> Settings -> GCC C++ Linker -> Library search path -> "${workspace_loc:/${ProjName}/lib}"
After the define libraries, I wrote the code in the documentation and compiled it.
#include <fmt/core.h>
int main() {
fmt::print("Hello, world!\n");
}
The code compiles without errors. But the problem is there are too many errors for core.h file. Some errors;
Type 'std::experimental::basic_string_view<Char>' could not be resolved
Invalid overload of 'parse_format_specs'
Return has value, in function returning void
There are errors like these. The software compiles and runs, but there are errors in both main and library files. Likewise, I did the same compiling and installing to use the library named spdlog. It also compiles and works, but a lot of errors occur. Am I missing something in the cmake processes? There are always errors when I import an external library. How can I solve it?
Suppose I have the next projects structure (to be more convient let assume that QtCreator is used as IDE):
|
|-build_minGW
|-build_msvs
|-...
|-Project
|-src
|-inc
|-...
Moreover, suppose I want to use some .json files to store settings of my program. So after every compilation program should be run from the respective 'build' folder. Where should I create this .json files (Project folder, 'build' folder or elsewhere)? Is it any common and correct way to do this automaticaly (e.g. if I create files in Project folder, they should be copied to the every build directory)?
I am configuring CMake build project on Windows for MSVC++ project.It build ok the executable,then installs it into a defined directory.In my cases that's:
${CMAKE_SOURCE_DIR}/x64/${CMAKE_BUILD_TYPE}/
The executable has got a folder in the same directory with files which it loads upon the launch.If I launch the .exe manually it opens up and runs ok.But I want to do it via ctest.
I defined ctest like this:
add_test(ENGINE_TEST1 ${CMAKE_SOURCE_DIR}/x64/${CMAKE_BUILD_TYPE}/MyApp.exe
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/x64/${CMAKE_BUILD_TYPE})
When I call from the cmd:
ctest
The executable is starting up but crashes immediately with the error:
Debug Error!
Program:../..../.../MyApp.exe
R6010 -abort() has
been called.
Indeed,when checking the CMake's Last Test.log file it shows that it runs the test not in "WORKING_DIRECTORY but in the directory where the MyApp.exe has been built by CMake.How do I change that?
As I am not CMake pro I am sure the following answer is not the optimal way to do it,but at least it works for me.
Again,I was trying to run ctest on an executable from within the directory into which cmake had installed it.The exe on the startup was trying to load dependent files which were in the same directory.But it was crashing because it couldn't fin the files.
It appears that the cmake default workspace directory is the directory where the cmake files and projects are generated.That's 'build' directory.So when the executable is launched via ctest it search the paths of the files to load relative to the build directory.
Now,CMAKE has 2 variations of add_test() method.One is simple with arguments:
add_test([test_name] [test exe path])
It doesn't take care of the working directory.
And another one which is explained here does include an argument for explicit setup of the working directory.
Frankly speaking,I wasn't able to get this advanced function working as it was demanding to supply some test .config which I didn't understand how to setup.So what I did,I used the simple add_test function.
And then I set the working directory to the location of my executable using this:
set_tests_properties(mytest PROPERTIES WORKING_DIRECTORY "${TEST_WOKRING_DIR}")
And it fixed the problem.
I have a few dll projects in a solution (some depending on each other)
Project1 -> Properties -> Linker -> Input -> Additional Dependencies -> Project2.lib
Project1 -> Properties -> Linker -> General -> Additional Library Directories -> $(OutDir)
All is working fine.
Projects are Win7Debug Win32, Win7Debug x64..... and a Win32 project with only Debug and Release configurations.
I would like to have all dll's for Win32 placed in one folder and the x64 ones in another folder. So I added the x64 configuration for the Win32 project, and changed
Project1 -> Properties -> Linker -> General -> Output File -> $(SolutionDir)/i386/$(TargetName)/$(TargetExt)
(for Win32 - similar change for x64)
all seemed fine - and I only received dlls in the i386 folder... until I had to rebuild and got
Warning 23 warning MSB8012:
TargetPath(C:\Path\Win7Debug\Project1.dll) does not match the Linker's OutputFile
property value (C:\Path\i386\Project1.dll). This may cause your project to build
incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and
$(TargetExt) property values match the value specified in %(Link.OutputFile).
This seems serious... and I don't want to have problems with missing dependencies (though everything seems to be working fine - and not just on my machine)
I changed
Project1 -> Properties -> Configuration Properties -> General -> OutputDirectory -> $(SolutionDir)/i386
(to match the linker output) but now of course I get lib and exp files in the same folder as the dll's.
Other than using post build script, is there a way to separate the output files ?
Should I just leave the settings how I had them and disregard the warning above ?
Note: I am not trying to separate the Platform/configuration output files... That is done automagically using the default output directory.
What I need is, for each platform, to place only DLL files in one folder away from anything else. Redirecting Linker output (and leaving project output to standard) accomplishes that - I just am not sure if it is correct. Logically I should not have any build problems since I am giving linker all the info it needs...
The standard approach is to leave all these properties unchanged (inherit from parent). In this case linker will create DLL and LIB in $(Output) directory, which by default is $(SolutionDir)$(Configuration).
You just specify the name for x64 configuration, and all output files will be separated automatically.
The standard (and the easest) way to link import library is to add reference to corresponding project in Common Properties / References page. Nothing else is required.
If, for any reason, it is impossible, add $(SolutionDir)$(Configuration) to Configuration Properties / VC++ Directories / Library Directories and add library to be linked to Linker / Additional Dependencies. If there are many projects in your solution, you may create Property Sheet for the solution and specify Library Directories only once.
I'm new to Ogre and tried to run the first tutorial, but I have faced a problem getting the
error message
OGRE EXCEPTION(6:FileNotFoundException): 'resources_d.cfg' file not found! in
ConfigFile::load at ../../OgreMain/src/OgreConfigFile.cpp (line 83)
Please help, its critical!
Another question:
Is cmake important for installing the Ogre sdk?
After getting ogre compiled/installed using cmake
on linux those two config files live at
/usr/local/share/OGRE/resources.cfg
/usr/local/share/OGRE/plugins.cfg
just import both into your ogre project
Once ogre is installed, your project does not need cmake
To get you going for the tutorials :
How to setup eclipse with ogre :
File -> New -> C++ Project -> EmptyProject
C/C++ Build -> Environment
OGRE_LOC /home/scott/src/ogre_src_v1-7-3
C/C++ Build -> Settings
GCC C++ Compiler -> Includes
${OGRE_LOC}/OgreMain/include
/usr/local/include/OGRE
${OGRE_LOC}/Samples/Common/include
/usr/include/OIS
GCC C++ Linker -> Libraries (-l)
OgreMain
OgreTerrain
OIS
CEGUIOgreRenderer
right click project -> Properties -> Import
General -> File System ->
ONLY import those 4 files from the tutorial project
(NOT dist, build, makefiles ...)
BaseApplication.cpp
BaseApplication.h
TutorialApplication.cpp
TutorialApplication.h
also import these files :
/usr/local/share/OGRE/resources.cfg
/usr/local/share/OGRE/plugins.cfg
Now you are ready to compile and run !
To add an Ogre model :
First do above steps to create an ogre project, assure it compiles OK. On execution it'll render a black screen - thats fine. Now to add a model (an Ogre) simply edit TutorialApplication.cpp so function createScene appears as :
``
void TutorialApplication::createScene(void)
{
Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
headNode->attachObject(ogreHead);
// Set ambient light
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
// Create a light
Ogre::Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);
}
CMake is critical for building the ogre sdk from source - I would not try to configure the installation yourself. If you are using the prebuilt sdk, cmake is probably unnecessary.
As far as your error goes, it happens to be that you are trying to load resources from the resources.cfg. I am unaware of your operating system, however, be sure that your resources.cfg is in the same directory as your binary. If you are using MSVC and running it through the debugger, make sure your working directory (found in Project Properties -> Debugging -> Working Directory) is set to the directory of your executable.