Where to set the -D variable in CDT IDE

F

fl

Hi,
I have a complete C project which is under Linux. It has a Makefile
(part of that in the end of this post, see below please). I can
compile it, no problem.

Now, I want to learn it in Eclipse CDT in OPENSUSE 12.1. I cannot find
how to setup the -D variable in CDT. The C function using that
variable is below the dot line. I tried several symbol configuration.
It turned out it took effect to all the C files. Many errors pop up on
that variable. I would like to know how to set -D variable only to one
C file using that variable.

Could you tell me how to do that?


Thanks a lot.





............................
C function:
//////
if (!initialized)
{
f = fopen(RAND_FILE,"rb");
/* f = fopen("randfile","rb");*/
...............

Makefile:
//////
modules:
$(COMPILE) bloio.c
$(COMPILE) chk.c
$(COMPILE) opeeen.c
$(COMPILE) monse.c
$(COMPILE) morse.c
$(COMPILE) moert.c
$(COMPILE) daaab.c
$(COMPILE) -DRAND_FILE=\"`pwd`/randfile\" rand.c
 
F

fl

Hi,
I have a complete C project which is under Linux. It has a Makefile
(part of that in the end of this post, see below please). I can
compile it, no problem.

Now, I want to learn it in Eclipse CDT in OPENSUSE 12.1. I cannot find
how to setup the -D variable in CDT. The C function using that
variable is below the dot line. I tried several symbol configuration.
It turned out it took effect to all the C files. Many errors pop up on
that variable. I would like to know how to set -D variable only to one
C file using that variable.

Could you tell me how to do that?

Thanks a lot.

...........................
C function:
//////
  if (!initialized)
  {
    f = fopen(RAND_FILE,"rb");
/*    f = fopen("randfile","rb");*/
  ...............

Makefile:
//////
modules:
        $(COMPILE) bloio.c
        $(COMPILE) chk.c
        $(COMPILE) opeeen.c
        $(COMPILE) monse.c
        $(COMPILE) morse.c
        $(COMPILE) moert.c
        $(COMPILE) daaab.c
        $(COMPILE) -DRAND_FILE=\"`pwd`/randfile\" rand.c

Further information is listed below when set symbol variable:
RAND_FILE value: \"`pwd`/randfile\" rand.c
It seems that the message changes the quote symbol '"' position in the
error message. I don't know the reason.

Thanks.


.....................
**** Build of configuration Debug for project ex_am ****

make all
Building file: ../rand.c
Invoking: GCC C Compiler
gcc -DRAND_FILE=\`pwd`/randfile\" rand.c" -O0 -g3 -Wall -c -fmessage-
length=0 -ansi -MMD -MP -MF"rand.d" -MT"rand.d" -o "rand.o" "../
rand.c"
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [rand.o] Error 1

**** Build Finished ****


**** Build Finished ****
 
F

fl

Hi,
I have a complete C project which is under Linux. It has a Makefile
(part of that in the end of this post, see below please). I can
compile it, no problem.
Now, I want to learn it in Eclipse CDT in OPENSUSE 12.1. I cannot find
how to setup the -D variable in CDT. The C function using that
variable is below the dot line. I tried several symbol configuration.
It turned out it took effect to all the C files. Many errors pop up on
that variable. I would like to know how to set -D variable only to one
C file using that variable.
Could you tell me how to do that?
Thanks a lot.
...........................
C function:
//////
  if (!initialized)
  {
    f = fopen(RAND_FILE,"rb");
/*    f = fopen("randfile","rb");*/
  ...............
Makefile:
//////
modules:
        $(COMPILE) bloio.c
        $(COMPILE) chk.c
        $(COMPILE) opeeen.c
        $(COMPILE) monse.c
        $(COMPILE) morse.c
        $(COMPILE) moert.c
        $(COMPILE) daaab.c
        $(COMPILE) -DRAND_FILE=\"`pwd`/randfile\" rand.c

Further information is listed below when set symbol variable:
RAND_FILE value: \"`pwd`/randfile\" rand.c
It seems that the message changes the quote symbol '"' position in the
error message. I don't know the reason.

Thanks.

....................
**** Build of configuration Debug for project ex_am ****

make all
Building file: ../rand.c
Invoking: GCC C Compiler
gcc -DRAND_FILE=\`pwd`/randfile\" rand.c" -O0 -g3 -Wall -c -fmessage-
length=0 -ansi -MMD -MP -MF"rand.d" -MT"rand.d" -o "rand.o" "../
rand.c"
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [rand.o] Error 1

**** Build Finished ****

**** Build Finished ****

Hi,
Even more strange to me now. I find that there are makefile,
objects.mk, source.mk and subdir.mk. I have checked all the IDE
property settings. There is no RAND_FILE parameter. But the new
generated subdir.mk always has the -DRAND_FILE= ... settings. This
cause the compiling complaint. I do not know how to make the CDT IDE
not generate this -DRAND_FILE in the subdir.mk. Do you know how to
change that?

Thanks again.


..............
# Each subdirectory must supply rules for building sources it
contributes
%.o: ../%.c
@echo 'Building file: $<'
@echo 'Invoking: GCC C Compiler'
gcc -O0 -g3 -Wall -c -fmessage-length=0 -ansi -MMD -MP -MF"$(@:%.o=
%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '

rand.o: ../rand.c
@echo 'Building file: $<'
@echo 'Invoking: GCC C Compiler'
gcc -DRAND_FILE=\`pwd`/randfile\" rand.c" -O0 -g3 -Wall -c -fmessage-
length=0 -ansi -MMD -MP -MF"$(@:%.o=%.d)" -MT"rand.d" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
 
J

Jens Thoms Toerring

fl said:
I have a complete C project which is under Linux. It has a Makefile
(part of that in the end of this post, see below please). I can
compile it, no problem.
Now, I want to learn it in Eclipse CDT in OPENSUSE 12.1. I cannot find
how to setup the -D variable in CDT.

'-D' isn't a variable, it's a compiler flag which you can use to
define a macro while invoking the compiler (and while '-D' is
used by several compilers for that purpose this isn't anything
the C standard requires).
The C function using that
variable is below the dot line. I tried several symbol configuration.
It turned out it took effect to all the C files.

What does that mean? There's a C function in which the macro
you set in an option of the invocation of the compiler is used.
But what are "symbol configurations"?
Many errors pop up on that variable. I would like to know how to set
-D variable only to one C file using that variable.

You don't tell what what you actually tried. That makes it
rather hard to give useful advice.
...........................
C function:
//////
if (!initialized)
{
f = fopen(RAND_FILE,"rb");
/* f = fopen("randfile","rb");*/
...............
Makefile:
//////
modules:
$(COMPILE) bloio.c
$(COMPILE) chk.c
$(COMPILE) opeeen.c
$(COMPILE) monse.c
$(COMPILE) morse.c
$(COMPILE) moert.c
$(COMPILE) daaab.c
$(COMPILE) -DRAND_FILE=\"`pwd`/randfile\" rand.c

You seem to have some problem that isn't related to C but
to Eclipse and the CDT plug-in (and mixed into this you
seem to rely on a shell that treats backticks in a certain
way and has a 'pwd' function). Just for the fun of it I
installed Eclipse and used it the first time in my life
and (when using a Makefile project or whatever it's cal-
led in Eclipse) setting a macro from the command line of
the compiler invoction the way you have it in your Make-
file worked out of the box quite fine. So you must have
done it somewhat differently - but there's nothing that
tells what exactly you did try...

I would guess your best bet for a good answer is to ask in
a forum or newsgroup dealing with Eclipse and CDT since
that's what your problem seems to be about. If you do that
it might be worthwhile to try to give a bit more of infor-
mation about what you actually did. Some of the error mes-
sages you did show in later posts may hint at some trouble
with Eclipse and the shell you use getting in their ways
about dealing with quotes and backslashes but that's some-
thing the C compiler has no influence over (it just gets
garbage input and then, of course, isn't able to do what
you want it to do).
Regards, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top