Gcc compiling when a header has macros

Hi guys!

I am having trouble compiling using gcc with a header in my code has a few macros.

Is there a way to do this?

Here is my line

gcc -lglfw "x:/Documents/UE Tools/glew-cmake/lib/libGLEW.a" main.cpp

main.cpp has a header in it and that header has a couple macros. When I try to build it does not reconize my macros. I can not move the macros to main.cpp, so that is not an option. For the life of my I can not find a way to do this build. Any ideas? Thank you in advance.
Last edited on
You don't link to a header, you #include it. Show your source code, or a simplified example that still reproduces the issue.

Edit: Original post was modified after I posted, making my post not make sense.
Last edited on
Edit:
OP trashed the question, but didn't improve any of the information needed to answer the changed question.
nothing to see here.
Last edited on

I think you have to wrap the macro in a function to activate it, otherwise it is ignored.

area.h
1
2
#define AREA(l, b) (l * b)
double area(double l,double b){return AREA(l,b);} 

Then with this tester in the same folder as area.h
1
2
3
4
5
6
7
8
#include "area.h"
#include <iostream>
using namespace std;
int main()
{
	cout<<area(3,4)<<endl;
	 cin.get();
} 

g++.exe "C:\TESTERS\testarea.cpp" -o "C:\TESTERS\testarea.exe"
Whoops, that line of code was a copy paste mistake, I fixed it.
oggin wrote:
I think you have to wrap the macro in a function to activate it, otherwise it is ignored.

That's not accurate. Macros are a text substitution facility built into the preprocessor. The expansion of the macro will be inserted where ever the preprocessor finds the macro. A macro does not have to be part of a function. It can be used in another macro. It can be used to define a global value. For example:
 
  constexpr int area = AREA(3,4);

Thanks guys, calling it a day for now, will look in to this more tomorrow, and yes, there are probably some other mistakes with that line that I am making, I am getting a handle on gcc still, little by little though I will get there.

Of course AbstractionAnon, the macro can stand alone in a .h file.
My mistake.
#include "area.h" just puts the .h code straight into the user code, thus the macro into the user code.
I am thinking of static or dynamic libraries.


Topic archived. No new replies allowed.