vscode intellisense can't find header files included in cmake project - c++

I have a cmake project that has:
A static library called Project1
A static library called Project2 that depends on Project1
An executable called Project3 that depends on both libraries
Everything is working as expected (makefiles, it is building and running normally, ...),
but the problem is that vscode intellisense just does not find the header files in the
folders specified using target_include_directories on each subdirectory.
The intellisense can find the default headers (iostream, vector, etc).
example: https://i.stack.imgur.com/XeVGW.jpg
I also tried putting the include directories in c_cpp_properties.json:
"includePath": [
"${workspaceFolder}/Project1/src/**",
"${workspaceFolder}/Project2/src/**",
"${workspaceFolder}/Project3/src/**"
]
But it also didn't work.
I also tried putting the headers/sources manually in all CMakeLists.txt files (without using file(GLOB_RECURSE))
But it also didn't work.
This project is just a small example I made to show the problem, but it also happens in all the other projects.
The project can be found here: https://github.com/gabrielmaia2/CmakeTest

Found it. The extension "C/C++ Clang Command Adapter" was showing the errors because clang was not configured. I just disabled it (since I'm not using it) and now its working as expected.

For those of you who are still experiencing this very irritating issue, the solution that worked for me was to just disable any C++ extensions, i.e. the Microsoft C++ extension pack, then enable them again.

Related

C++ detours linking issue

I have problems building my code that is using static lib detours. I am trying to do an old basic CTF. For that I want to get into detours.
Whenever I try to build my .dll file I get an issue
LNK2019 unresolved external symbol _DetourTransactionBegin#0 referenced in function _DllMain#12
Now, I have built the detours library using 3 different version of the visual studio dev console.
I have tried firing 'vcvars32.bat' and then using nmake to build the library which was able to build it, but I get the above error during linking my .dll. I have also tried building it with 'vcvarsamd64_x86.bat' and then using nmake to build it which also was able to build the library, but I still get the same error as above during linking.
I have tried the usual stuff: the include folder for detours.h is added to C++/General/Additional Include Directories.
Under Linker/Additional Library Directories I added them as follows: "C:\temp\det_retry\lib.X64";"C:\temp\det_retry\lib.X86";%(AdditionalLibraryDirectories).
And also under Linker/Input/Additional Dependencies I have the following: detours.lib;%(AdditionalDependencies)
What am I missing here? This is a blocker for me for a couple of days and I am reiterating the same steps trying to figure out what's missing but I cannot see. I'd really appreciate the input.
I am sure I am using the newest version because I have downloaded (cloned) detours from the ms github page.
It appears your "Additional Library Directories" are setup incorrectly or contain invalid entries rather. They look like actual library file entries (i.e. pointing to some specific files) versus being only directories (e.g. "my/lib/path/for/my_project/"). Visual Studio's naming conventions are somewhat cryptic but they should be directory entries only. There should be an entry to whatever directory contains the detours.lib file (e.g. "MyProject/Libs/MSDetour" ... where MSDetour is a folder with the "detours.lib" in it) and then Visual Studio should find the library and link everything correctly.
As a side note, if you are using the Visual Studio developer console for building your project/solution you might want to look into CMake ... it is, in my opinion, significantly easier to work with (less "settings" digging) and maintain in the long-run.

Build failed with no stated reason on Segger Embedded Studio after adding custom source files

I'm modifying a simple example project (blinky) from the nRF SDK. I added a header file and a .c file in a new folder inside the project directory then added that path ./lib to the common preprocessor user include directories. I then included the header to main.c.
I can compile the new library on its own but when I build the whole project, I get Build failed error with no stated reason to follow up.
Here is an image of that:
Does anyone here know how to beat this?
I haven't used Segger Studio specifically, but it seems to be the CrossWorks IDE underneath.
In CrossWorks, you have to do the following:
Download & install all relevant libs from inside the IDE, under Tools -> Packages -> Install packages. Grab your specific target MCU as well as any specific boards or libraries you'll be using. In case some needed lib is missing here, you will get very weird errors.
In the project, click on the project name itself in "project explorer". Then in the properties window, check settings (this is a bit different in different versions of CrossWorks, might have to right click and pick properties in older versions). Under "user include directories" you should have something like this:
$(DeviceIncludePath)
$(TargetsDir)/NameOfMCU/Include
$(PackagesDir)/CMSIS_4/CMSIS/Include
$(ProjectDir)/NameOfDirectory
Where "NameOfMCU" is the name of the MCU family used, CMSIS should be there in case you are using any ARM, "NameOfDirectory" is the name of your custom directory (you can add several).
Also, get the debug build working first, before switching to release build.

Configuring VSCode with CMake on Qt - ui_*.h files can't be found

I'm trying to configure VSCode to run with a project written in C++ and Qt, using the Microsoft C/C++ Intellisense extension.
Some files include Qt ui headers, in the format:
#include "ui_filename.h"
However, these are underlined with red squiggles and the message:
#include errors detected. Consider updating your compile_commands.json or includePath. Squiggles are disabled for this translation unit (/path/to/my/workspace).
cannot open source file "ui_filename.h"
These files are in a directory build.debug/, which is a subdirectory of my root workspace directory.
I've tried to use the CMake Tools extension, by configuring it with only this:
"cmake.copyCompileCommands": "build/compile_commands.json"
build is the project's directory for all things to do with building.
The configuration for the C/C++ extension has these relevant lines:
"includePath": [
"${workspaceFolder}/**",
"/usr/include/x86_64-linux-gnu/qt5/**"
],
...
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
However this still doesn't solve the problem. I've also tried installing the CMake Tools Helper extension, which ironically doesn't help.
I'm not really sure where to go from here. Everything else works fine, Qt definitions are all recognised and all normal headers a recognised. I've checked, and the ui header files definitely exist in my workspace. What can I do? Help is very much appreciated.
It seems you're gonna have to manually add the files' paths into your project's include path. Take a look on the manual section here for more info.

Eclipse can't resolve <includes> despite seeing them in project's Includes

I have a C project opened in Eclipse that uses a third party library. I added a /usr/local/include/ and /usr/include/ to the project's includes and the Project explorer window shows all required header files correctly.
The build also works fine but the Editor part of the ide doesn't seem to be able to resolve #include pointing to the 3rd party header files correctly.
I've tried restarting Eclpse and rebuilding the index. I've also tried both default settings and Enable project specific settings for indexer, nothing work. Individual source files don't have specific configuration.
Copying the header files to ~/devheaders and pointing Eclipse there solved the issue, no idea why. Permissions on the header files were fine.

"Include can't be found", how to fix it?

I am developing using OpenSceneGraph. I installed it from a user-runnable installer.
When I try to compile an application using OpenSceneGraph, I have this error :
Lexical or preprocessor error : Include cannot be found for all <osg/*> includes like <osg/AnimationPath>.
The file is available here /Library/Frameworks/osg.framework/Versions/92/Headers/XXXX So following this solution on how to "add existing frameworks" to the new Xcode, I added osg.framework to the project.
any idea is a welcome.
I am using :
IDE Xcode 4.5
Clang 4.1
OS X Mountain Lion
When compiling you will have to add the include files using the -I option of the compiler and also possibly add library directory using the -L option of the compiler(the options may be a bit different if you are using compiler different from gcc).
I guess both library and the include directories for this product should be subdirectories of the install destination you have chosen. For the include directory of course look for directories containing some kind of header files .h or .hpp and for the libraries look for .lib or .dll doesn't the library documentation mention what includes and libraries you need and where you can find them?
EDIT: you will also have to tell xcode where to search for your includes. I tried googling it and here is one of many results on how to add a directory to the include path of a project.
You will have to located which directory to add to the include path. It seems they set some environment variables in the official documentation for that.
Hope this helps.
You'll need to add /Library/Frameworks to the "Frameworks search path" in the project settings.