wxWidgets include files all in same folder? - c++

I'm on a Xubuntu machine. I've downloaded and compiled the source, did the make install.
I'm trying to create a simple wxFrame class, but when I include <wx-3.0/wx/frame.h>, it says Can't resolve type wxFrame. When I look inside frame.h, it includes a reference to <wx/toplevel.h>. Both frame.h and toplevel.h are in the same folder. Why does the compilation place the include files all in the same folder, but the paths to the files are different?
I am using CLion IDE and the include/lib paths are set by cmake's FIND_PACKAGE().

#ShrimpCrackers,
It is generally advisable to start you project by copying one of the sample code into you project and then set you project properties to the output of wx-config --cxxflags and wx-config --libs.
So what you should do is to copy the wxWidgets/samples/minimal/minimal.cpp over to the directory where you project is, fix the project properties and recompile.
BTW, you don't have to do make install. You might want to compile debug and release versions of the library on one machine which defeats the purpose of installing. You just use the compiled version of the library

Related

How can Codeblocks find my header files even without adding any search paths

I'm learning to use OpenCV (and C++) in Codeblocks. What confuses me, however, is that when I start to include header files from OpenCV in my main.cpp file, Codeblocks automatically suggests to me the files as shown in the image below.
I have not included any search paths to project build options, so how is this possible that Codeblocks can find the files? Is there some other variable working here that I'm unaware of?
Note that I'm a beginner with both Codeblocks and OpenCV and that I only have a little experience with C++.
Thank you
Of course when you install an IDE like code::blocks by default, it knows about standard path for library on your OS.
On my OS -> Ubuntu that is /usr/include
It only searches on a standard path, except you add one. If you install your library by command-line, it goes to the standard place, if you installed manually, then it depends on your option you added to installation. I can not see you screen-shot but it has access to /usr/include by default.
For more detail on Linux and OpenCV
And here is a screen-shot of codeblock on Ubuntu that I added some 3rd-party library
NOTE:
if you install any libraries by command-line, just use it.
But if you have installed them manually, you need to add 2 things to codeblock.
1. First is your path for header file
2. Second is your path for linker
And you see it in screen-shot that say: Search Directory
First is for header and second is for linker

CLion indexer does not resolve some includes in the project directory

I have a CLion C++ project that has the following structure:
project
---->my_includes
| ----> my_own.hpp
---->source
----> my_app
----> my_src.cpp
The first line of my_src.cpp is
#include "my_includes/my_own.hpp"
I use an external build system that requires this inclusion format. The problem is if I use a function in my source file defined in the included header, CLion says "Cannot find my_own.hpp" if I try to hover over the inclusion.
I tried marking the include directory as containing Project Source or Headers but this didn't fix it. Any ideas?
You need to create a CMakeLists.txt for CLion to be happy. It is enough to declare all the source files, you don't have to convert your scons (or any other build system) to cmake.
You don't even have to write the CMakeLists.txt by hand, you can ask CLion to do it:
File | New CMake Project from Sources... (since CLion 2019.2)
File | Import project ... | (older CLion)
and then point at the directory containing your project.
Now edit the generated CMakeLists.txt and add a cmake command to tell CLion where to find the includes (actually to tell the compiler, and CLion will reuse that information).
Since your source files use the include as #include "my_includes/my_own.hpp", you need to tell cmake the base directory containing directory my_includes:
include_directories(.)
Where the dot means the same directory as the one containing the CMakeLists.txt.
I tested with a project reproducing your layout and from my_src.cpp I can navigate to my_own.hpp.
Then to build you still have to use scons in a console. It is also possible to add a cmake command, add_custom_target() that will call your scons (or your make, or whatever), so that you can also navigate from CLion to the build errors.
This should be a CMake-based project to open correctly in CLion.
Check CMake basics tutorial if you are new to CMake: https://www.jetbrains.com/help/clion/2016.1/quick-cmake-tutorial.html
And for MakeFile + gcc (g++) projects, you can add the flag -I /Dir/To/Your/Project.
If CLion still shows errors with #include after recompiling the make file, delete the .idea folder and restart CLion.

How to correctly include Dlib in Eclipse project?

I'm currently trying to use the Dlib c++ library in my own project. So I included the main folder of dlib to my project. I also added the dlib/all/source.cpp to my project. When I try to compile the code of the svm_c_ex.cpp example in my own test.cpp file, I only get:
fatal error: dlib/svm.h: No such file or directory
The section Dlib: How to compile didn't help me and I couldn't find further information online. Any help is appreciated!
You need to compile the DLib library first, using the instructions from the website.
cd examples
mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake is a famous tool to build software on multiple platforms. It generates required files first and then you can compile the library using those generated files later.
You need to add the "include" directories (the folders where the headers exist) in your project configuration. I'm quite not sure of where exactly to add in Eclipse CDT.
After that, your program gives linker error because the the header files only contain skeletons of your library code. Actual implementation need to be linked with "linker options" in project properties. You need to add your library's .lib/.a files with your program. I don't exactly remember where is linker options in CDT (I'm talking in Visual Studio context)
Basically for any library you want to use in any C++ project:
You need to include HEADERS in your project properties
You need to link to actual implementation of the library. You can read about
static and dynamic libraries (Someone on SO must have given an
awesome explanation)

Setting up OpenGL in CodeBlocks

I am having trouble getting the right setings in order to use OpenGl in CodeBlocks.
I have used the instructions from this tutorial: GLUT but for my project to run I need the following flags: -lGL -lGLU -lglut which I can set in the Other linker options tab from Build options. When I do this, the compiler says cannot find -lGL -lGLU -lglut. What do I have to install in order for these libraries to work? GL.h GLU.h glut.h? and if yes how can I link them to the project? By adding them in the Link libraries tab? And also from the project tree which appears in Build options does the name of the project have to be selected when I install these libraries, or Debug or Release?
In Build options, if I select the name of the project, at Link libraries I have the following: glut32, opengl32, glu32, winmm, gdi32 but I don't remember giving a path for them. Are they correct or do I have to change them as well?
I would like to mention that the created project is a GLUT project and that I am using Windows 7.
The issue is that you are telling Code::Blocks to look for opengl32.lib, glu32.lib, etc. but not where to look for them. Hence the error during linkage.
Under Project Build Options -> Search Directories -> Linker you need to add the directories containing your OpenGL libraries. Example:
Note that the directory containing your OpenGL libraries will probably be different from mine, since according to the link in your question they should be wherever you put MinGW.
You will also need to make sure you add to the Search Directories the location of the OpenGL header files. Example:
This is the folder that contains the gl subdirectory.
After downloading the GLUT bin zip file (considering you already installed codeblocks earlier), you extract all the files in it and copy those three files separately. The glut32.lib goes to c:\program files\mingw\lib and copy glut32.dll to c:\windows\system and copy glut.h (header file) to c:\program files\mingw\include\GL
Then open codeblocks and go for new project>GLUT. Then set up the GLUT location to Mingw(in program files) and then finish. It worked for me just fine.

Eclipse C++ project not resolving LD_LIBRARY_PATH include variables

I have a C++ project I am importing and it is using activemq libraries. After I import the project, I set the LD_LIBRARY_PATH variable under environment to point to
/usr/local/include/activemq-cpp-3.4.2
This allows the project to see all the libraries for activemq and I can see it show up in my includdes folder in the project explorer. When I go to Build Project, I am getting tons of errors to references of includes/objects that are inside /usr/local/include/activemq-cpp-3.4.2. The interesting thing is that the binary is still being produced, yet there are about 80 errors due to the library files not being found. How is the binary being made? Also, what must I do to the LD_LIBRARY_PATH environment variable so the project is properly including those files?
I have tried launching eclipse with the
./eclipse -clean
But that didn't seem to help. Any ideas are welcome, and thank you in advance!
EDIT:
I am using Eclipse Juno with C++ verseion 4.1.2 on Redhat 4.X
LD_LIBRARY_PATH isn't used for locating include directories. It's used to inform the system of a list of directories to search for shared libraries: compiled support libraries, not e.g. SDKs for Eclipse.
You should use the project's properties to add to the places that are searched for includes: C++ General->Paths and Symbols->Includes
Also use the properties - not LD_LIBRARY_PATH - if you do need to link against other libraries: : C++ General->Paths and Symbols->Library Paths
Finding header files is not the purpose of LD_LIBRARY_PATH. That environment variable is to tell the OS where to start looking for shared libraries — *.so files. The OS looks for those when preparing the execute your program. The compiler uses the include path to search for headers when it encounters an #include statement in your source code.
Don't modify LD_LIBRARY_PATH to affect compilation of your program.
Eclipse lets you set your include path in your project options.