I need to have full path of C++ files (name of file is not neccesary). It musn't to be depended on path of execution.
I can use __FILE__, hovewer it gives me only name of file. I was seeking in boost::filesystem, but I only found boost::filesystem::current_path() - unfortunately it gives me path of directory from which I run program.
I looking for path of cpp file, not path of exe. I need it for other tool to generate groups of cpp files after directory of cpp files.
Any ideas?
Edit:
Maybe it is possible to use bash script which gives actual directory of cpp file (not sh file)?
Related
I've been testing some stuff in Visual Studio after some time not working with VS, And I ran into a problem where I include a file and I get this error:
Cannot open include file 'spdlog/spdlog.h': No such file or directory
but I have the right path, in Project settings I have the right path set as an additional Include directory and the file is there. but the Thing is, when I take the file and move it one directory up and change the include path so that it now points one directory up (where the file is now) it suddenly works. Example:
File Path: Project/lib/spdlog/spdlog.h
Include directory: Project/lib
this Works
File Path: Project/lib/spdlog/spdlog/spdlog.h
Include directory: Project/lib/spdlog
This doesn't work
I don't want to include the lib directory since I have more libraries in it and it would just mess some stuff up, so I want to include every library (like spdlog for instance) separately. Does anyone know what might be causing the issue ? Also the error isn't shown when writing the code only when I try to build the Project.
Maybe you are missing spdlog library.
I suggest you check out this issue.
For debian-like distros you should be able to download it via apt-get: apt-get install libspdlog-dev.
I have a project path where I have created an executable testsd:
Caspian#Caspian-VirtualBox:~/TestProject/build/linux/debug/bin/testsd
The project directory and heirarchy is as following:
/TestProject
|-build/linux/debug/bin
|-ExtLib/folder/lib(containing .a and .so files)
|-ExtLib/folder/src(containing multiple sub folders with .cpp files)
|-ExtLib/folder/include(containing multiple sub folders with .cpp files)
|-src(containing multiple sub folders with .cpp files and mainc.pp)
|-tests(containing Runtests.cpp and catch.hpp files)
The problem is when am running this executable (./testsd), I am encountering the following error:
./testsd: error while loading shared libraries: libuastackd.so: cannot open shared object file: No such file or directory
The libuastackd.so files is contained in ExtLib/folder/lib and ExtLib/folder/src/stack/lib folders. Can anyone help, how can I overcome this problem?
Thanks rG
You might set the LD_LIBRARY_PATH environment appropriately.
See this. Read ld-linux.so(8).
There is some way to set LD_LIBRARY_PATH for your entire session, e.g. by editing appropriately ~/.login or ~/.bashrc or ~/.bashenv or ~/.profile etc ... and this would alter the behaviour of any program you start after, including some Eclipse IDE
Read Drepper's How To Write Shared Libraries, notably for other solutions -e.g. appropriate -Wl,-rpath settings (which is probably what you really should use).
I have a C++ program compiled with MinGW on Windows 7 that calls fopen(), specifying a file with a relative path. The program works fine if you run the executable in it's own directory, but I've noticed that fopen() will not find the specified file if I were to run the program with command line in a different directory. For example, if my executable "foo.exe" and specified file "bar.txt" are located in "C:\project\build\" and I run the exe while in "C:\project\", fopen() will not find the file. Is there some workaround for this using the code or compiler flags?
I can see this being necessary to access resources which are in a specified location relative to the executable, though without the absolute path of the executable file itself being known. I would suggest getting the absolute path to the executable file, probably using one of the methods described in Get path of executable, and then either changing the process's working directory to the parent directory of the executable, or constructing an absolute path to the file you want to open by resolving the relative path you have against that directory. Then you can pass the result to fopen().
I am a "very" beginner of OpenCV. I just downloaded it for my Windows and extracted.
I have read this post: http://opencv-srf.blogspot.ro/2011/09/capturing-images-videos.html about how to read webcam and I copied and pasted the code in a C++ file I created in "include" folder of OpenCV extracted archive.
When I try to run the program I get this error: Error in: /opencv/build/include/opencv2/highgui/highgui.hpp - opencv2/highgui.hpp: No such file or directory.
What should I do?
Thank you all!
EDIT
I opened: "/opencv/build/include/opencv2/highgui/highgui.hpp" and I can see that it includes this path "opencv2/highgui.hpp". If I change it to "../highgui.hpp" it works but I get other errors like this for other files... What should I do?
The problem is that you are not supposed to create your "cpp" file in the OpenCV "include" directory. You need to create it in a separate directory and then add OpenCV "include" as additional include directory for the compilation step.
The way to achieve this depends on your C++ development environment. If you are using Visual Studio, then you need to open project property pages, go to "C/C++ -> General" and add the path to OpenCV "include" directory to "Additional Include Directories". In case of some other compiler/IDE, you can find out how to do this by reading the corresponding documentation.
I'm trying to figure out where to save multiple .txt files so that i can have a command line tool project in Xcode read directly in from them while running it.
I understand that Xcode compiles everything to a folder, DerivedData, which i have saved in the same location as my source code for each project respectively.
can i save multiple .txt files anywhere in the DerivedData folder or include it in the build settings and phases so that when i run the command line tool i can type the name of a file, it will read in from that file.
By default the compiled/linked binary will look into its own directory for files.
For example, my binaries are at ProjectName/Build/Products/Debug/ and therefore it will look for files from that dir.
You can use relative path from that folder to the outside.
Or, you can create a symbolic link to another directory (on Terminal):
ln -s source_dir target_file
target_file must be located in the same directory as your binary. And you can reference the other files like "target_file/file1.txt", etc.