ANSI C Compilation linking problem

B

Ben

I get an error when the compilator tries to link the object files of
my program. I have the files group.h and group.c that use a struct
define in logic.h and two fonctions define in logic.c.

The program compile group.o fine, but when trying to link, I get an
error in group.h saying that a struct that is defined in logic.h
cannot be found. Include logic.h is explicitly call in group.h because
it used an instance of that struct. What I dont understand is how,
when the program compile, it is able to find the reference to the
struct in logic, but when he tries to link, he does not find it
anymore.

If I take all the code from logic.h and logic.c and I copy it in
group.h and group.c respectively, it links fine.

I don't know what else to try, any ideas is welcome.

Benoit Grimard
 
R

Richard Bos

I get an error when the compilator tries to link the object files of
my program. I have the files group.h and group.c that use a struct
define in logic.h and two fonctions define in logic.c.

The program compile group.o fine, but when trying to link, I get an
error in group.h saying that a struct that is defined in logic.h
cannot be found.

This sounds suspicious. By the time you're linking, you shouldn't be
refering to group.h any more - by then they should all be object files
created during the compilation stage. What precisely is the error you
get?

Richard
 
J

john_bode

Ben said:
I get an error when the compilator tries to link the object files of
my program. I have the files group.h and group.c that use a struct
define in logic.h and two fonctions define in logic.c.

The program compile group.o fine, but when trying to link, I get an
error in group.h saying that a struct that is defined in logic.h
cannot be found. Include logic.h is explicitly call in group.h because
it used an instance of that struct. What I dont understand is how,
when the program compile, it is able to find the reference to the
struct in logic, but when he tries to link, he does not find it
anymore.

If I take all the code from logic.h and logic.c and I copy it in
group.h and group.c respectively, it links fine.

I don't know what else to try, any ideas is welcome.

Benoit Grimard

Can you show us the exact commands you are using to compile and link,
and the exact error message you are getting?
 
B

Ben

Can you show us the exact commands you are using to compile and link,
and the exact error message you are getting?


The ANSI-C code Im writing is to be run on opentv middleware platform,
and it just ended up that modified GNU compiler didnt catch an error
while making logic.o. I think because it postponed the definition of a
pointer to a struct because the include for that struct was missing.
So the logic.o wasnt really compile and he forgot that it wasnt
complete and still tryed to link it. So, he wasnt able to find the
struct in the not complete logic.o, so it gave me an error in group.h.
I have yet to understand why the compiler didnt catch that or write an
error code on the good object at least.

^^^^^^
I have include the file which contain the struct and it compile and
link fine, this is just a guess of what I think happened.

It was my fault after all, but the compiler didnt helped me to find
the error at all.
 
J

Joe Wright

Ben said:
The ANSI-C code Im writing is to be run on opentv middleware platform,
and it just ended up that modified GNU compiler didnt catch an error
while making logic.o. I think because it postponed the definition of a
pointer to a struct because the include for that struct was missing.
So the logic.o wasnt really compile and he forgot that it wasnt
complete and still tryed to link it. So, he wasnt able to find the
struct in the not complete logic.o, so it gave me an error in group.h.
I have yet to understand why the compiler didnt catch that or write an
error code on the good object at least.

^^^^^^
I have include the file which contain the struct and it compile and
link fine, this is just a guess of what I think happened.

It was my fault after all, but the compiler didnt helped me to find
the error at all.

Most of my C programming involves only one 'source.c' file. As soon as I
have two translation units, I do compiles with 'make' and a carefully
constructed makefile. It saves a lot of time.
 

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
474,166
Messages
2,570,901
Members
47,442
Latest member
KevinLocki

Latest Threads

Top