CLion not working for any file in another directory - c++

I have a directory structure as follows:
libs/
sdw/
glm-0.9.7.2/
glm/
...
src/
ProjectName.cpp
The sdw directory is full of classes with .cpp and corresponding .h files. Inside any of these files, if I type #include " then it auto-suggests header files within this directory. Syntax highlighting also works for any included classes, as does suggestions for methods etc.,
However, inside ProjectName.cpp, I get no such suggestions for header files, and syntax highlighting plus method suggestions are not present. The only things that work are from the std lib like vector etc.
No files get any highlighting etc., for anything inside the glm directory.
Here is a relevant part of the CMakeLists.txt that was provided to me:
set(GLM_INCLUDE_DIRS libs/glm-0.9.7.2)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS} ${GLM_INCLUDE_DIRS})
include_directories(libs/sdw)
add_executable(ProjectName
libs/sdw/Utils.cpp
libs/sdw/Triangle.cpp
src/ProjectName.cpp)
Inside files like libs/sdw/Utils.cpp I am doing: #include "Triangle.h". This works.
Inside src/ProjectName.cpp I am doing: #include <Utils.h>. This
runs but does not work in the way I want, as described above.
And in everything I am doing #include <glm/glm.hpp> which does not
work in the way I want.
EDIT:
I noticed when opening CLion it promps me to clean the project when loading it. If I click OK then it gives me these errors:
No rule to make target 'all'.
Make execution failed with exit code = 2
No compilation commands found

Deleted .idea and selected CMake project this time (chose Makefile last time)

Related

Successfully Included File, now dealing with semantics issues

Earlier I asked for help in including an external library called Eigen in xcode 4. I finally managed to get it to include the header file I wanted to use, Array, by going to build phases, link binary with libraries, and then adding the sub-folder within the Eigen archive where Array.h was located, Core. I also added the filepath to Core's parent directory, src, in header search paths.
When I finally managed to add the line of code #include <Core/Array.h> without it getting highlighted as an error, I ran the application (which worked previously) and XCode said that the build failed, with the error messages citing semantic issues. I checked the error message and they include, "Uknown identifier 'Array'" in a file named Array.h.
All of the header files are in src and according to the Eigen website, they are all that's needed to use Eigen with c++. I've attempted to reformat the binary links so they go to src instead of Core, and adjusting the buildpath to lead to the parent directory of src, ensuring that all header files can now be accessed, but I'm still getting semantics issues. Does anyone have a solution to this?
You generally want to include the Core file, not the individual .h files, i.e.
#include <Eigen/Core>
There are exceptions, but again, you won't be including the .h files, those are used internally. Additionally, it appears that your include path points to the ./Eigen/src/ directory. You want to move it up two directories so that when you write #include <Eigen/Core> it finds the Core file correctly. The files that you'll most likely include are the extension-less ones in the Eigen directory.

Freetype invalid preprocessor directive Eclipse

I've downloaded the latest version of FreeType and want to get the source code running in my program. I'm programming in Eclipse and I've copied all the Freetype files into my project. I've listed them under ProjectName/Source/FreeType2/..
I've added compiler include directories for the new folders, so my GCC C++ compiler knows where to look for them. However, if I build my project, an error occurs on the last line of the following code:
#include <ft2build.h>
#include FT_WINFONTS_H
#include FT_INTERNAL_DEBUG_H
I did some research and the macro file FT_INTERNAL_DEBUG_H is defined as <internal/ftdebug.h>. The file is present in my system and the macro file FT_WINFONTS_H compiles like a charm! I think it's got something to do with my directory stucture somehow. How should I change my directory structure in order to get things compiled succesfully? My current structure is like this:
ProjectName
Source
FreeType2
devel
docs
include
config
internal
objs
src
I know I used two "source" folders, but this shouldn't be the problem, right?
The error message I get is Invalid preprocessor directive: #include FT_INTERNAL_DEBUG_H
Thank you for your time ;)

Xcode - header files issue with .cpp file

I have imported my project from windows to mac and Is using xcode to compile the project.
I have managed to fix most error and bugs from the porting process but there is one bug/error I am unable to determine why its not working as it should. This probably due to my lack of knowledge of xcode but was wondering if anyone is able to help me with this problem.
The problem is this;
I have a two sub folders in my project, once called include and another called source. Of course include contains all the header files and source contains all the cpp files and such.
Example:
Root/
Include/
Header.h
Source/
test.cpp
Now in the build settings in the xcode project, I have added $(SRCROOT)/Include/ in the Header Serach Paths. So therefore I presume that xcode will include any header files in the Include folder.
So in the test.cpp class I add #include "Header.h". When I click build I get an error saying "'Header.h' file not found".
Im not entirely sure what I am doing wrong, of course I can do this for example - #include "../Include/Header.h" but that's going to be a pain going through all the cpp files in my project (which is a lot).
I was just wondering if anyone else came across this problem?
Thanks for reading.
In general you need to add the headers to the User Header Search Paths, which if you search the help in XCode will give you the format you need to pass the directory as.

Question about C++ folder structure for header file

I'm quite new in C++ after few years in Java and eclipse, I got little bit confusing using code::blocks, no autogenerate setter/getter and also implement interface :D.
I wanna ask about code structure in code::blocks, I create new console application, my header will be put to Headers/include folder called Employee.h, then .cpp will be put to src folder.
Now I create main class (I put outside of src folder) who will call the header, I just append the include code like this :
#include "Employee.h"
sure then the errors appeared after compiling:
error : Employee.h: No such file or directory.
how to link the header to the main class properly?
this is my folder structure :
updated :
It works, my include folder needs to be added on build options.
Really thanks
You need to add your include directory to your compiler's include path. This is going to be compiler-specific. e.g., if your structure is:
code
code/src
code/include
and you're running g++ from a terminal in the 'code' directory, you'd need to run (assuming your .cpp is Employee.cpp):
g++ -Iinclude src/Employee.cpp
I suspect you're running some sort of IDE, though: if so, do a search in its help for "include path" and it should tell you how to set it up correctly.
If you want to include your employee.h you must #include "employee.h" not Employee.h. Those are two different files.
You shouldn't be adding include paths to your build options for header files that are actually part of your project. It didn't find the header file from the EmployeeTest.cpp because you didn't use the full relative path.
You need:
#include "include/Employee.h"
You should only be adding include paths to your compiler for additional libraries that aren't added to the typical /usr/local/include or /usr/include directories.

Troubles at Including (Linking) a static library inside another one

I'll try to explain shortly what I want to do:
A project using a static library which have another one as depandency.
It produce a project called MyProject linking on MyLib1 linking on MyLib2.
Here is the compile order:
MyLib2
MyLib1 (linking to MyLib2)
MyProject (linking to MyLib1)
I'm using Visual Studio 2008 and I have some troubles at defining include.
When linking, I use the property "Additional Include Directory" (on project property C/C++ node).
This seems working between MyProject and MyLib1 but not MyLib1 and MyLib2.
For Exemple: I've a file in MyLib2 called foo.cpp; Using #include "foo.cpp" makes visual studio telling that foo.cpp is unknow (missing file or folder).
To ensure it's NOT a wrong path I gave, I've done many attemps like following: copy-paste the path shown in Command Line (used to compile the library) into win explorer: I well see the source code of my second library. I've remake the project many times and each times I used differents names (forcing me to pay attention to this) and everything seems well defined (but not "including").
The only way I actually find to make it works: using #include "c:\\foo.cpp" as include... Very nice for portability !
Here is a Zip of the Solution to test it yourself and tell me what's wrong: MyProject.rar
Thanks for taking some time to help me !
Lucyberad
First, never include *.cpp files.
Second, use forward declaration of your external functions:
void appellib2(void);
void appellib1(void)
{
appellib2();
}
Third, right-click each project in the Solution Explorer, and select "Project dependencies..." and set-up proper dependencies: MyProject -> MyLib1 -> MyLib2.
At last, in properties for MyProject, set up additional dependencies MyLib1.lib.
Now I can build and run your project without errors.
UPDATE
Never rename *.cpp to *.h just to solve linking problems. If you have a definition in your *.h file you will unable to include it twice or more.
Here is your project YourProject.rar.
I've changed .cpp to .h. I Know I've never to include a CPP file but it was for testing purpose.
I've added prototype of each function but it doesn't works better (It don't include the file mylib2.cpp, the prototype is better but not usefull in this test).
I've set up project dependencies. It still fail.
I've set up additional dependencies MyLib1.lib to MyProject (I think this was the next error I would be able to find, producing a linking a error).
With theses modifications, I still got include error mylib2.h: no such file or directory.
Here is the new archive: MyProject.rar
If you reach to get it working, can you make me an archive of the working solution?
Thanks,
Lucyberad.