I am compiling on windows with cdt/mingw. I like to compile warning free. I get the following warning:
auto-importing has been activated without --enable-auto-import specified
on the command line.
The following page suggests the way to deal with it is to just adding that option to the command line of ld.
4.8 ld and WIN32 (cygwin/mingw)
The question is thus, how do you change the default command line switches for the built in toolchains?
I would also like to set the warning level of gcc.
You have to send the parameter to the linker via gcc's -Wl parameter:
-Wl,option
Pass option as an option to the linker. If option contains commas,
it is split into multiple options at
the commas. You can use this syntax to
pass an argument to the option. For
example, -Wl,-Map,output.map passes
-Map output.map to the linker. When
using the GNU linker, you can also get
the same effect with
-Wl,-Map=output.map.
So, you need (and me too :)) -Wl,--enable-auto-import.
For controlling warning levels, see the official docs.
Hi so far I have found a partial solution to this problem. I have not found how I can change the default toolchain options, but I have found how to change them on a project basis.
In project->properties->C++-build->settings
It seems to make more sense if it would be in tool chain editor, but it isn't.
There you have a tab called Tool Settings and looking down there is MinGW C++ Linker->Miscellaneous.
Here on the right you can add extra linker options. Above you also have the compiler and warning settings are implemented as checkboxes which is nice.
So far at least I have gotten started, only a pity I have to do that over for every project individually.
Oh for further confusion, this is not always there, and I have some old projects from before I installed MinGW and who thus have no real toolchain installed. In that case the settings pane only has the Binary Parsers and Error Parsers tabs, so it looks completely different. The secret is in having the Tool Settings Tab. Very dynamic and for the rainforest like settings dialog of eclipse also very confusing.
Related
For the sake of migrating compiler options to ARM using Xcode, I'm looking for a comprehensive documentation for clang c++ compiler/linker options. The closest I could get was this page, however:
Many options aren't explained, e.g. -arch, -arch_errors_fatal, -sub_umbrella and many more.
There are options in the Xcode command line that are missing in this doc, e.g. -Wno-four-char-constants, -Wshorten-64-to-32 etc.
Is there any place where I could find a full documentation with generous explanations for each option? Please note, I don't need the meaning of the options I gave here as examples, only for a comprehensive reference.
I think that in general, you need to refer to Clang documentation and to the Cross-compilation using Clang.
Update:
If you cannot find the argument you need, please go to the bottom of the page to Search Page.
Paste the argument and press "Search".
If the argument is supported, you will see its description.
For example, if you look for -arch_errors_fatal it will show this:
Static analyzer report output format (html|plist|plist-multi-file|plist-html|sarif|text).
-ansi, --ansi
-arch
-arch_errors_fatal
It is not very descriptive but on the top of the same page, you can see:
Introduction
This page lists the command line arguments currently supported by the GCC-compatible clang and clang++ drivers.
Hence, this specific flag was added for compatibility with the GCC, so you need to look for it in the GCC's documentation.
So you do the following:
man gcc.
Press /, paste -arch_errors_fatal, and press Enter. This is the search in the man page.
press n until you find the relevant information.
For this specific flag it will show you:
-arch_errors_fatal
Cause the errors having to do with files that have the wrong architecture to be fatal.
I forgot that MacOS comes without GCC nowadays, so you can lookup the GCC manual page online.
Looking for information about open-source tools might be not very straight-forward but yet feasible.
Hope it helps.
I'm trying to use vscode with arduino but have no success.
The problem seems to be something with the libraries path.
But I havent been able to fix that !
I'm on linux.
"message": "#include errors detected. Please update your includePath. IntelliSense features for this translation unit (/home/harold/Arduino/Saaf_Curing/Saaf_Curing.ino) will be provided by the Tag Parser.",
I don't know how to find my includePath.
I'm not able to do any advices given in vscode.
I wonder if vs code is the right direction at all as it seems complicated ?
Although the question mentions Arduino, the following suggestions apply basically any time VSCode tells you to "update your includePath".
What is includePath?
The includePath is an attribute in c_cpp_settings.json, which is in the .vscode folder of the main folder you have opened in VSCode using File → Open Folder.
You can edit c_cpp_settings.json directly, but it is usually easier to use the "C/C++ Configurations GUI". To do that, open the Command Palette (Ctrl+Shift+P) and run "C/C++: Edit Configurations (UI)". Then look for the "Include path" setting.
The includePath tells VSCode (specifically the IntelliSense component of the C/C++ extension) where to look when resolving #include "filename" directives. That allows VSCode to see definitions of symbols defined in those files.
So should I fiddle with includePath when VSCode tells me to?
Not at first! Before changing the include path, if you haven't already, first set the "Compiler path" to point at your C/C++ compiler, and set "IntelliSense mode" to match the compiler as closely as possible.
You may also need to adjust the Compiler arguments, particularly if the compiler is capable of generating code for multiple targets, for example, both 32-bit and 64-bit code. (If you don't know what that means, skip it at first.)
Next, in Command Palette, run "C/C++: Log Diagnostics". The output will show you which compiler VSCode found and what it detected as its built-in include path and preprocessor defines.
Then, run these commands in a shell:
$ touch empty.c
$ gcc -v -E -dD empty.c
Here, I have assumed you are using gcc as your compiler. If not, substitute the actual compiler command name. If your compiler is not a variant of GCC (for example you are using the Microsoft cl.exe compiler), you'll need to look at its documentation or Google to find switches that print the predefined macros and include paths (e.g., see here for cl.exe).
Compare the output of the above command to what VSCode shows in its C/C++ diagnostics output. Hopefully they are very similar. If not, try adjusting the Compiler path, IntelliSense mode, or Compiler arguments. Once you've gotten them as close as possible by adjusting just those three settings, go on to the next step.
Now adjust includePath if necessary
If there are still significant differences between the compiler built-in configuration and what VSCode detects, fix that by (in the C/C++ settings UI) modifying the Include path, Defines, and C/C++ standard fields. Re-run the C/C++ Log Diagnostics command to see the effects.
It is probably not necessary to add all of the pre-defined preprocessor symbols. This really only matters if there are #ifdef directives that depend on them, and which are causing VSCode to see the wrong code as active. I suggest only adding predefined symbols if, while browsing your code, you see a specific case that VSCode gets wrong.
Finally, if your project has header files in places that the compiler does not search by default, that is, you normally have to pass -I switches on the compiler command line, add those as well to the Include path. The same goes for any -D arguments, which must be added to the Defines.
This is due to the extension is missing some includepath when initialize
add the missing lines into your c_cpp_properties.json
"includePath": [
"<arduino ide installation folder>\\tools\\**",
"<arduino ide installation folder>\\hardware\\arduino\\avr\\**",
"<arduino ide installation folder>\\hardware\\tools\\**",
"<arduino ide installation folder>\\hardware\\arduino\\avr\\cores\\arduino"
]
Also add "defines": [ "USBCON" ] under "configurations" to make Serial class work with intellisense
Try using platformIO extension it makes your life easier. Personally I use VScode with platformIO for my Arduino and ESP32 projects.
I just successfully wasted an hour finding solution to this problem on stack overflow but all in vain and now I have founded the solution which is, if you are using linux, just have to install the g++ compiler from your terminal,
sudo apt install g++
" and you are good to go.
For those using WSL, it's a common error, resolved by:
installing Remote-WSL VS-Code extension
setting c_cpp_properties.json includePath to ["${workspaceFolder}/**"] and intelliSenseMode to "linux-clang-x64" (or other intelliSense mode)
close VS-Code and open it again from your WSL termnial, you'll see the Status Bar icon as on the screenshot
Now the #include error should be gone
For more information follow the link
I had the same issue and spent hours trying different solutions, and finally, I realized I had a misspelling in "iostream". It's not an answer to this question, but if you have fallen here with the same error, check spelling as well.
Cause of the Problem:
My C/C++ Compiler got saved as /use/bin/clang and this was showing the error in my computer.
Operating System: Ubuntu 2022.04
Solutions:
Open Your VSCode and click Settings (at bottom left corner generally).
Now click at Open Settings (JSON) icon (at top right corner) and open the json file.
Add below code in between last part of main {} bracket [If you don't have the bracket then create one].
"C_Cpp.default.compilerPath": "/usr/bin/gcc",
"C_Cpp.default.intelliSenseMode": "linux-gcc-x64",
This has solved my problem and I think it will solve the problem for any Linux/Unix OS.
In case, if this doesn't work then try with:
"C_Cpp.default.compilerPath": "/usr/bin/g++",
"C_Cpp.default.intelliSenseMode": "linux-gcc-x64",
If you have Windows Operating System then Use the path of your GCC compiler instead of /usr/bin/gcc [this will be something like C:\MinGW\bin].
I did follow the suggestions on the documentation to enable clang code completion, but it seems that on the most recent version there is no option to add search paths and compiler flags separately, I tried adding compiler flags on the search path window, but is not showing any evidence that it caught the new paths:
Any idea what I'm doing wrong?
You don't need to set the paths separately for clang code completion to work.
You just need to re-build (i.e. clean follow by build) your project once.
If everything is done properly, you should see in CodeLite's build log lines similar to:
codelite-cc g++ ... (or codelite-cc clang++...)
The codelite-cc utility will collect the search paths (and macros and other flags) passed to the compiler and will pass them back to CodeLite, so it will pass it to libClang for getting the proper code completion for your code.
I created a new solution for zlib 1.2.7, set it up as a static library, added the necessary headers and source files from ./zlib/contrib/minizip and got it to compile just fine. I then linked it against libpng (also as a static lib), which also compiles fine. Then, I linked libpng to my graphics engine project (also a static library)... still no errors.
But as soon as I link my main project to my graphics engine, I get several LNK2026 errors regarding crc32.obj, deflate.obj, inflate.obj, d3dxplane.obj, d3dxvec4.obj and other zlib/directx related modules. It's telling me that they are coming from my graphics engine lib, so I've decided to fix this by adding /SAFESEH:NO to my linker flags for the corresponding projects.
NOTE: I should probably state that all projects are set to target x86, NOT x64.
The problem, however, is now I'm getting:
warning LNK4044: unrecognized option '/SAFESEH'; ignored which results in the same LINK2026 errors in my main project.
If I open up a visual studio command prompt and type LINK /? it confirms that /SAFESEH is a valid linker option. I get the same error when I use /SAFESEH (without the ':NO'), and if I omit it entirely then my main project simply refuses build.
What's going on here? How do I get around this?
by adding /SAFESH:NO to my linker flags
Well, you mis-spelled it. Maybe in your question, maybe in the linker settings, the kind of coincidence that tends to explain why something that should work doesn't work.
It is available without having to type it in, do favor doing it that way. Project + Properties, Linker, Advanced, scroll down the right panel, "Image has Safe Exception Handlers" setting. Use the combobox to select No.
A quick google shows this indicates you need to recompile the offending modules with appropriate compiler settings.
Note that this flag is only works for x86 targets. If you're targeting 64-bit, you'll get this error regardless.
Also, from http://msdn.microsoft.com/en-us/library/9a89h429(v=vs.80).aspx, which may be relevant:
The most common reason for the linker not to be able to produce an
image is because one or more of the input files (modules) to the
linker was not compatible with the safe exception handlers feature. A
common reason for a module to not be compatible with safe exception
handlers is because it was created with a compiler from a previous
version of Visual C++.
It would be helpful if you provided version numbers of your compiler, and how your copy of zlib was built (did you build it yourself, and if so, with the same compiler?).
In Visual Studio 2017
Right click on Project -> Properties -> Configuration Properties -> Linker -> All Options ->
Image Has Safe Exception Handlers = No (/SAFESEH:NO)
I have updated my Ubuntu box to 11.10 and then Eclipse also have been updated to 3.7.0 Indigo with CDT 8.0.1
Then the following problem occurs:
I have included the vector header file but the compiler said that Symbol 'vector' could not be resolved. I also defined #define int Comparable, but Eclipse also said Symbol 'Comparable' could not be resolved and so on....
Although lots of errors occur, compiling was finished successfully!
I have tried to use g++ to compile the code, it had no problem.
The problem is that there are a bunch of include directories that are missing from the indexer's perspective.
Adding the following worked for me, but may depend on your particular setup where they actually exist:
/usr/include/c++/4.6.1
/usr/include/
/usr/include/c++
/usr/include/c++/4.6
/usr/include/x86_64-linux-gnu
/usr/include/asm-generic
/usr/include/c++/4.6.1/x86_64-linux-gnu/
They can be set in Project>Properties>C++ Include Paths
Presumably, in the future, the platform specializations for the CDT will included these automatically. I recall reading that somewhere, but cannot provide a reference.
Time after time a crash of Eclipse, the VM or the computer or even just long months of development start to wear down the stability of the workspace where Eclipse stores everything.
Check the <workspace dir>\.metadata directory to get an idea of just how much Eclipse generates and stores in your workspace. Every time you add a plugin, upgrade a plugin, remove a plugin that puts and changes information in your workspace.
A proof is that this issue usually comes just after upgrading Eclipse. (In my case to Indigo).
The easiest way to fix up a dusty workspace is using the -clean command line argument to the eclipse.exe executable.
Eclipse help docs tell us what this command does:
if set to "true", any cached data used by the OSGi framework and
eclipse runtime will be wiped clean. This will clean the caches used
to store bundle dependency resolution and eclipse extension registry
data. Using this option will force eclipse to reinitialize these
caches.
There are three ways one can use the -clean command line argument:
Edit the eclipse.ini file located in your and add it as the first argument on the first line.
Edit the shortcut you use to start Eclipse and add it as the first argument.
Create a batch or shell script that calls the Eclipse executable with the -clean argument.
The advantage of step 3 is you can keep the script around and use it each time you want to clean out the workspace.
This page solved the problem to me!Hope it can help everybody else.
In the project properties, go to C/C++ Build > Tool Chain Editor, tick Display compatible toolchains only, and select Linux GCC and click Apply button.
Now if you go to C\C++ General > Paths and Symbols, you will see new list of include paths added. If you rebuild index, the error messages should go away.
The code analysis is causing this. It's not actually compiling the code but just doing some static checks for quick feedback. Unfortunately I don't know how to fix it, I just disabled it. Sorry I'm at work so I don't have CDT in front of me but I think it's something like:
Window > Preferences > C++ General > Code Analysis
Go there and un-check all the boxes to disable it.
When you create a C++ project (in my case from existing code) you have to set the 'Toolchain for Indexer Settings' to the compiler you use ('GNU Autotools Toolchains' in my case).
After this 'Path and Symbols' will show the correct path to the include files of your compiler.
The bugs will disappear.
This setting was useful only during creating the project, setting it later did not help.
In indigo 3.7.2 version (and up may be) your changes can be effect after reindexing. Eclipse ask for "reindexing". Lower versions can require a manual reindexing header tags etc.
Updated index option to active build configuration works for me,
also I removed some files from the file list of being indexed up-front,
Ok here is what worked for me:
deleted the path to the header files I created from the include path
compiled the project (obviously the compiler complains since it is missing user-defined headers)
reinserted the path to the header files I created
compiled the project again - worked perfectly
I can't explain the case :(
I am answering here because this is the closest question to my problem.
I used QT Eclipse integration with Helios (3.6.2) with no major problems. I was using mingw 4.6.2, which I had installed to c:\mingw. I wanted to upgrade to Indigo, which fixed some minor issues I was having with CDT.
However, under Indigo (3.7 SR2) Eclipse began underlining trivial functions, as being unresolved, such as:
function 'fprintf' could not be resolved
function 'memset' could not be resolved
even though #include was not underlined, could be opened, and included fprintf in the header. And even though the code itself compiled fine.
If I went back to Helios, the problems went away.
I tried reindexing, to no avail. I checked my include paths, and they were:
c:\mingw\include
C:\MinGW\lib\gcc\mingw32\4.6.2\include
At first, I had just included the first, but not the second. But then I searched for "unresolved includes", and stdio.h was including stdarg.h, which wasn't in the main include folder of mingw, so I added the second. But still, printf was not resolved, and there were no more "unresolved includes".
I created a new C++ project with one class. I added stdio.h, the paths above, and a call to fprintf. It was underlined! Even though other things from stdio were not underlined.
Now I knew that it wasn't just a Qt problem.
I worked around on this for a while before I read the bottom post here suggesting removing the include paths and compiling. I didn't believe it would work but gave it a shot. Amazingly, even though the compile failed, the error went away!
It was then that I took another look at the include paths. They had been updated by the compile step to the following:
c:/mingw/lib/gcc/mingw32/4.6.2/include-fixed
c:/mingw/include
c:/mingw/lib/gcc/mingw32/4.6.2/include
c:/mingw/lib/gcc/mingw32/4.6.2/include/c++/backward
c:/mingw/lib/gcc/mingw32/4.6.2/include/c++/mingw32
c:/mingw/lib/gcc/mingw32/4.6.2/include/c++
These were marked as "built-in" values which I assume means they weren't added by me and could get updated the next time I run a build.
So, I guess the lesson is, including every single include path under mingw, even if Eclipse doesn't find it to be an unresolved include.
The next step was to put all these paths into my Qt project. Unfortunately, after doing so, the unresolved functions were still there. It appears to be some sort of bug with the Qt C/C++ include paths which are different from the CDT C/C++ include paths.