Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Makefile project configuration
Makefile project configuration [message #1828232] Thu, 04 June 2020 14:20 Go to next message
Karolis Milieška is currently offline Karolis MilieškaFriend
Messages: 4
Registered: June 2020
Junior Member
Hello,

My use case includes using Eclipse CDT basically as a very fancy text editor with superb indexer.
I have mixed C and C++ Makefile Corss ARM GCC project. I am not using Eclipse's builder, only invoking make.

Please help me configure my workspace. I have read a lot of resources online already.

I have:
1) created "Makefile Project with Existing source" (problem described below also applies to C or C++ projects as well)
2) enabled "CDT Cross GCC Built-in Compiler Settings" provider with following invoke command:
C:\_env\gcc\9-2019-q4-major\bin\arm-none-eabi-g++.exe ${FLAGS} -E -P -v -dD "${INPUTS}"

and it works by filling up settings entries.
The problem is that since it is g++, it adds same entries for both GNU C and GNU C++ languages (.c and .cpp files). That results in C sources having C++ defines (like __cplusplus), which breaks indexer itself.

Also, I once had header file, which had "Syntax error" on extern "C" linkage specification under #ifdef __cplusplus. It was only included in few C source files. When it got included into C++ source file, syntax errors where gone. Note that it is only Eclipse related, it was building successfully before and after.

How should I configure Eclipse properly, to be able to work with mixed C/C++ projects?

Re: Makefile project configuration [message #1828250 is a reply to message #1828232] Thu, 04 June 2020 23:32 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Use gcc and a file with either a .c or .cpp extension.
GCC selects the proper compiler based upon the extension.
So for C builtins: gcc -E -P -v -dD no.c
For C++ builtins: gcc -E -P -v -dD no.cpp

no.c and no.cpp are empty files.

You can override it with the -x flag.
https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#Overall-Options
You can only pick languages that gcc has been configured with.

That said, CDT uses files with .c and .C and changes the compiler.
You can view this by allocating a console (checkbox in provider tab).
gcc -E -P -v -dD <workspace>/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.c
g++ -std=c++17 -E -P -v -dD <workspace>/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C
but this is in a project that has both C and C++ natures.
Don't know what would happen if one of them is missing.
Or if a cross compiler prefix is being used.

[Updated on: Fri, 05 June 2020 07:45]

Report message to a moderator

Re: Makefile project configuration [message #1828264 is a reply to message #1828250] Fri, 05 June 2020 08:13 Go to previous messageGo to next message
Karolis Milieška is currently offline Karolis MilieškaFriend
Messages: 4
Registered: June 2020
Junior Member
Can you please be more specific? No ofence, but things you mention seem like out of context.

Provider is only one command. You say that output is parsed for multiple languages?
Re: Makefile project configuration [message #1828271 is a reply to message #1828264] Fri, 05 June 2020 10:48 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Quote:
Provider is only one command. You say that output is parsed for multiple languages?


Yes.
Two separate executions of the provider command with different files.
One for C and one for C++.
If the command uses ${COMMAND} the proper compiler will also be used as determined by the selected toolchain.

It's the one place outside of a Managed Build that uses the toolchain.

[Updated on: Fri, 05 June 2020 10:53]

Report message to a moderator

Re: Makefile project configuration [message #1828279 is a reply to message #1828271] Fri, 05 June 2020 13:45 Go to previous messageGo to next message
Karolis Milieška is currently offline Karolis MilieškaFriend
Messages: 4
Registered: June 2020
Junior Member
By your insights I went deeper and found that it is as you say: two executions of the same command. I have changed g++ to gcc and that provides two different outputs instead of the same as with using g++.

That solves my problem and things are working as expected for what I can already see.

Though I have few more kind of related questions and would appreciate your know-how:
1. Is it legit a way to not use MBS at all and only configure "C/C++ General -> Preprocessor Include Paths, Macros etc."? What other side effects it may have? Again, not for building, just using as "fancy editor".
2. Is it possible to configure ${COMMAND} without setting a toolchain or other MBS settings?
3. In my project, I use .h for C code headers and .hpp for C++ code headers. Lets say I have smth.h containing
#ifndef SMTH_H_
#define SMTH_H_

#ifdef __cplusplus
extern "C" {
#endif

// ...

#ifdef __cplusplus
}
#endif

#endif

If smth.h file is included only in C source files __cplusplus (as an example) is not defined and preprocessor directives indexed and colored accordingly. But as soon as any other C++ source file included the same smth.h, __cplusplus (as an example) in that header file is seen as defined. That is bad, because it might break code navigations is some particular scenarios.

Thank you in advance.
Re: Makefile project configuration [message #1828280 is a reply to message #1828279] Fri, 05 June 2020 13:58 Go to previous messageGo to next message
Karolis Milieška is currently offline Karolis MilieškaFriend
Messages: 4
Registered: June 2020
Junior Member
I have noticed, that same is valid for other defined symbols. See example below.

// Scenario 1. All good, smth.h: line 3 is seen "inactive"
1. // smth.h
2. #ifdef SOME_NUMBER
3. 
4. #endif

1. // smth.c
2. #define SOME_NUMBER
3. #include "smth.h"

// Scenario 2. smth.h: line 3 is seen as "active", which affects code navigation
1. // smth.h
2. #ifdef SOME_NUMBER
3. 
4. #endif

1. // smth.c
2. #define SOME_NUMBER    // this line does not affect anything in this scenario
3. #include "smth.h"

1. // smth.cpp
2. #define SOME_NUMBER
3. #include "smth.h"
Re: Makefile project configuration [message #1828283 is a reply to message #1828280] Fri, 05 June 2020 15:06 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Quote:
Is it legit a way to not use MBS at all and only configure "C/C++ General -> Preprocessor Include Paths, Macros etc."? What other side effects it may have?


The Managed Build (assuming that's what you mean by MBS) is really to generate makefiles. The builtin provider borrows from it's toolchain but can be bypassed.

Quote:
Is it possible to configure ${COMMAND} without setting a toolchain or other MBS settings?


I've never tried but suspect you can't. It seems to be dynamic.

---

I'm not quite sure what you are getting at with (3).
The Indexer isn't a compiler although it seems to act like one.
It remembers only the last definition of symbols it encounters.
Doing otherwise defeats the purpose of having an Indexer which is to quickly find things.

If you have multiple definitions that are arbitrarily selected for configuration purposes
then you might want to look into having separate projects with one for each configuration.

Previous Topic:Why Eclipse don't "open" function source by Ctrl+Click
Next Topic:Changing Project Name...
Goto Forum:
  


Current Time: Thu Sep 12 16:11:15 GMT 2024

Powered by FUDForum. Page generated in 0.25285 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top