Eclipse CDT, how to make it NOT search for system headers? - include

I'm porting a C project compiled on linux to an arm platform using Eclipse Luna on Ubuntu 16.04
When I switch from CC=gcc to CC=arm-none-eabi in the Makefile I get a lot of missing headers and that's ok, that's what the porting job is about.
What bothers me is that when I CTRL-click on a symbol Eclipse doesn't open the corresponding file for the arm toolchain. For instance if I CTRL-click on <time.h> it does NOT open:
/media/BUILDS/arm_gcc493/arm-none-eabi/include/time.h
but instead it always reverts to its linux system counterpart, in this case
/usr/include/i386-linux-gnu/time.h
because that's where gcc would look for but I'm compiling with arm-none-eabi-gcc instead!
I don't want Eclipse to do that because debugging gets really confusing. If I have a problem with the header/source I'm actually trying to compile with, I want Eclipse to open me that file and not the default system one. I fiddled with Project Properties and Eclipse Preferences but with no luck.
Even worse, whenever <sys/socket.h> is included I get an error because the arm toolchain does not have socket.h but if I CTRL-click on it Eclipse takes me to /usr/include/i386-linux-gnu/sys/socket.h
I dont' want that, if the header needed for compilation is not there, it's just not there. I don't want Eclipse to show me other stuff, how do I do that?
The project was created importing into the workspace "Existing Code as Makefile Project" under C/C++
Thank you very much
EDIT:
I did the proper thing and started from scratch creating a project for the Cross ARM GCC Toolchain (with the proper plug-in). My mistake was creating a "Linux GCC" Project and pretending that Eclipse understood what I was trying to achieve just by launching a different "make" command. If, however, you can't restart from scratch, the accepted solution instructs you on how to fix the situation manually.

To resolve this situation you need to update the Preprocessor Include Paths, Macros, etc. setting to use your custom-prefix GCC.
To make the change:
Open Project Properties (Right-click on project and choose Properties)
In C/C++ General -> Preprocessor Include Paths, Macros, etc., choose Providers tab
Select CDT GCC Built-in Compiler Settings
Uncheck Use global provider shared between projects
Replace ${COMMAND} with arm-none-eabi-gcc or arm-none-eabi-g++
Alternatively, you can also edit the same setting at the workspace level to affect all the projects in your workspace. Go to Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery tab instead.
Here are some screenshots that may help.
Before:
Project Properties:
After:

Related

Code::Blocks & WxWidgets Matching Release configuration

I am attempting to start a new project in Code:: Blocks (v17.12) using WxWidgets (v3.1.3) on Windows (10).
(For context, I am new to compiling- I'm a script coder trying to branch out. So... don't be afraid to talk to me like I'm an idiot. I'm prepared to accept that possibility.)
I downloaded the official 3.1.3 source, expanded it to "D:\code\wxw"
I successfully compiled it using mingw32-make that came with Code::Blocks-- there is a directory "D:\code\wxw\build\msw\gcc_mswudll" and "D:\code\wxw\lib\gcc_dll", the latter containing .dll files.
So I go into code blocks, and I:
Create New Project -> wxWidgets Project
Select wxWidgets 3.1.x
Project Title "HelloWorld", under D:\code\C++\tinker-- everything else autofilled.
Project details-- my info.
Preferred GUI Builder - None. Application Type - Dialog.
wxWidgets' location: D:\code\wxw
Compiler: GNU GCC
Selected "Create Release Configuration" because that's how it was compiled.
It provides an Output dir of "bin\Release\" and an Objects output dir of "obj\Release\", which I do not change.
Selected use DLL, built as monolithic, and enable Unicode-- the latter matching my compile settings.
When I click next, it tells me "A Matching Release configuration cannot be found in the wxWidgets directory you specified. This means that the Release target of your project will not build."
I've found multiple hits searching on this error message, but they all devolve into discussions of monolithic vs polylithic compiling and critique of other compiler settings and not actually addressing the problem.
EDIT:
Based on http://wiki.codeblocks.org/index.php?title=WxWindowsQuickRef
I used the following settings for compiling. I set them in config.gcc
BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1 CXXFLAGS=-fno-keep-inline-dllexport
The most important page of the wizard is the 8th page. Based on the settings you gave above, it should look exactly like this:
Also, instead of giving the path on the 6th page, I would define a global variable named wx in codeblocks like this:
Then on the 6th page, you would enter $(#wx) instead of the actual path. This will make using your projects much easier if you ever upgrade the wxWidgets library. You'll only need to change the location in the global variable settings.

How can I force Xcode to use a custom compiler?

I want to force Xcode to use a custom compiler ('clang-llvm' build from the src) so I can use the clang plugin. My Xcode version is 7.3.1.
People say it is possible with custom toolchains. I didn't make a research on them because easier solution worked well for me:
It is also possible to run frontend plugins directly by setting appropriate "build settings" of Xcode. (Several ways to do this, you can set them on the command line for instance: xcodebuild build FOO=bla.) Here are a few build settings that I found useful to inject C flags:
OTHER_CFLAGS, OTHER_CPLUSPLUSFLAGS or to replace the compiler(s) and linker(s):
CC, CPLUSPLUS, LD, LDPLUSPLUS, LIBTOOL
The same approach works to control the "analyze" action: CLANG_ANALYZER_EXEC, CLANG_ANALYZER_OTHER_FLAGS
Disclaimer: some of those build settings are undocumented (afaik). Use at your own risk.
(Taken from [cfe-dev] Compile/refactor iOS Xcode projects)
For me it was enough to define the following User-Defined Settings in Build Settings of Xcode projects:
CC=my-c-compiler
CXX=my-cxx-compiler
LIBTOOL=my-linker-for-static-libraries
If you use CMake, the way to inject your compiler automatically is to use
set_target_properties(your-target PROPERTIES XCODE_ATTRIBUTE_CC "${YOUR_CC}")
set_target_properties(your-target PROPERTIES XCODE_ATTRIBUTE_CXX "${YOUR_CXX}")
Couple of years ago I've written an article that addresses exactly the problem you describe: Creating and using Clang plugin with Xcode
To enable custom clang you need to actually patch internals of Xcode.app itself, it is technically doable but:
it will break when you update Xcode
it will work correctly on your machine
the version of a plugin and your compiler should match, i.e.
they should be compiled using the same tree
So in general it doesn't really scale, so be careful :)
There's a somewhat obscure feature of Xcode where it supports "alternative toolchains". For example, Swift.org provides installable toolchains for Swift built from current sources.
Unfortunately, while Apple's documentation describes how to install and use such alternative toolchains, it doesn't describe how to create them. There are scripts in the Swift source base which build a toolchain and you can look at them to figure out how it's done. They are in https://github.com/apple/swift/tree/master/utils. Start at build-toolchain, which calls build-script and go from there.
Method 1: Change the User Defined settings
Under the project or target Build Settings add the User Defined settings for
CC=/path/to/cc
CXX=/path/to/c++
This is useful if you have a single compiler or linker you want to call, or if you want to call out to a trampoline that decides what to call on the fly.
Method 2: Create a complete custom toolchain via plugin
Using Clang LLVM 1.0.xcplugin as a template (found in the Xcode.app plugins folder), you can modify the plist to point at your own alternative compiler and linker.
This OLLVM on iOS tutorial walks through it.
From project setting go to build setting with target selected. then select All beside the Basic from the top bar. then under build option you can see the compiler option.
Refer below screenshot,
Update :
I think you should refer Using C and C++ in an iOS App with Objective-C++ and this tutorial.

How to enter custom GCC compiler option in Build Options

There seem to a variety of questions like this one without any clear solution that is true for Xcode 7 (or even other versions of Xcode).
I have a version of GCC that I'd like Xcode to use when it compiles. It is not the standard GCC but customized for a different platform. I can specify and use this compiler fine in Eclipse, but would rather use Xcode. The Build Options only list LLVM and nothing else. When I try to add via "other" in that section, all I get is this empty popup:
What goes in this box? I would think that it should be no big deal for Xcode to simply use a GCC that I have available at a specific path on my system, but this appears to be quite complex.
Update: Apparently there is a supported mechanism for installing externally-provided tool chains in Xcode that I wasn't aware of. For example, one can download packages from swift.org that install alternative tool chain packages into /Library/Developer/Toolchains or ~/Library/Developer/Toolchains. Once one of those is installed, Xcode has a GUI option to switch the active tool chain.
There was a recent change to the Swift sources to include a script for building one's own custom tool chain from them.
If you view the Quick Help for that build setting (View > Utilities > Show Quick Help Inspector) or configure the build settings view to show setting names instead of titles (Editor > Show Setting Names), you'll see that that setting is GCC_VERSION.
If you look that up in the Build Settings Reference, you find:
GCC_VERSION
Description:
Numeric identifier. Identifies the GCC version to be used to compile
the target’s source files. When the target’s “System C rule” is set to
GCC System Version (instead of a specific version number), this build
setting is not available in Run Script build phases.
Values:
2.95.2
3.1
3.3
4.0
Default value:
GCC system version.
Specified in:
Project Info > Rules > “System C rule.”
Target Info > Rules > “System C rule.”
Affects:
GCC_VERSION_IDENTIFIER.
That's actually a bit out of date. It says it's specified by fiddling with a build rule (not setting) called the "System C rule". You used to change the version there but now there's a direct build setting for it.
Anyway, this probably doesn't help you do what you want to do. I doubt there's any value you could put in there that would do something useful, let alone use a third-party compiler.
However, the explanation does have a hint. It mentions the System C build rule. You could modify the build rules on the Build Rules tab of the target configuration screen. You can find the System C rule and press the button to copy it to your target, which will let you specify a custom script to process C files (including Objective-C and C++).
Implementing such a script is non-trivial. The inputs, expected outputs, and required behavior of the script are not well documented. There are various environment variables available for the use of such a script. Some are the build settings. You'll need to translate the relevant settings into compiler options. For example, translate the CLANG_WARN_BOOL_CONVERSION setting into the corresponding -Wbool-conversion option.
Some of the other environment variables indicate which file you should operate on, such as INPUT_FILE_PATH, INPUT_FILE_NAME, etc.
You need to tell Xcode what file(s) your rule outputs. These can be based on the input environment variables/settings, such as $(OBJECT_FILE_DIR)-$(CURRENT_VARIANT)/$(CURRENT_ARCH)/$(INPUT_FILE_BASE).o.
In general, this is just not something that Xcode makes easy.
Someone wrote a plugin that will allow you to use gcc from Xcode.
http://hamelot.io/programming/add-gcc-compiler-to-xcode-6/
If you have a custom gcc then you would need to change the paths around etc but the plugin should work.

Qt Creator: Projects that use other projects as libraries

I've written a small library as a Qt project using Qt Creator, now I want to create a small GUI application that can be used to test it as part of the development process, so it could be like this:
Project root at:
~/code/mylib
Library project and associated code:
~/code/mylib/corelib/corelib.pro
GUI test tool and associated code:
~/code/mylib/libgui/guitool.pro
So far I've only been able to make things work by setting up LIBS+= in the GUI project's .pro file, manually building the library, copying the library's .a file to the GUI directory, and rebuilding the GUI project. A tedious process. Worse: I'm developing the project now on Linux but need to make it build on Linux and Windows, and this manual build style will probably make that harder.
I suppose there's a way to do make Qt Creator aware of the relationships between the projects, so for example building the GUI tool in debug mode use the debug version of the library, or making changes to the corelib would necessitate a build in the GUI, building on some OS would use the libraries OS-configuration...etc
This kind of thing is a couple of clicks away in Eclipse and Visual Studio, but I can't seem to get it working in QtCreator. I've tried "Add library->Internal library" and creating a 'subdirs' project but neither seems to work. I feel it's probably a simple step that I'm missing somewhere, any help?
Try again to use subdirs feature. It have own wizard "Project with subdirectories", but in your case it's easier to write it manually (in example I've added "ordered" to ensure that order of compilation is always correct).
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = corelib guitool
Than you can add libary to your GUI application with wizard (accessible from context menu inside .pro).

Using Xcode for generic C/C++ development

I'd like to use all the power of Xcode for generic C/C++ projects but I can't figure out what are the basic steps to configure a new Xcode project and attach it to an existing source tree of a legacy, plain, C/C++ project.
Creating a new empty project, attaching it to a source tree and configuring a build target (using GNU Make) was a really silly task.
I can't figure out how to enable source code indexing in order to enable source refactoring tools, searching and fast-jumping and all the amenities that makes the Xcode programmer's life great.
Moreover I'd like to use the internal debugging facilities…
Does anyone point me to a tutorial, a hint or whatever could be useful?
Thanx
I've found a (dirty) path to enable refactoring tools:
I've added a new standard «console target» to the project and added all the source files under the Build Phases > Compiled Sources.
Refactoring tools now works. Having two targets doesn't seem to be a relevant issue (elegance apart)
Personally, I wouldn't attempt to use legacy Makefiles, even though I think there's some support for that.
Typically what I do with a traditional C/C++ project is to store my XCode project folder at the root of the project. So it might look like:
--myApp
--src
--inc
--myApp Xcode
I then drag the src folder and inc folder into the project navigator. This gives me an Xcode project to compile with on the Mac, and then I have the traditional Makefile for compiling on Linux (actually, I prefer CMake for other platforms, but either way works).

Resources