I am using Code::Blocks and mingcc to produce an executable from some heritage c code circa 1998. Compiles OK. Linking problems.

Even though I can use the Code::Blocks IDE to see where the parameters are declared in header.h files and implemented in main code c files, I get "undefined reference" errors for 17 parameters.

I am not posting any code at the moment, but looking for possible explanations, which I can investigate.

What am I missing?

Finstonm

Undefined reference means you've declared a name but not provided a definition anywhere. This usually happens when using a library's header without linking to the library.

To clarify, each of the parameters is declared in a header, .h file, which is included by a .c file which, in turn, contains the implementation. I can see this declaration of the parameter and its implemetation by using the Code:: Blocks IDE. I can also see the line(s)in the other.c files where the parameter is used - these are the ones which show the error of "undefined reference" when I link the .o files, which compile OK.

The problem is with these other .c files which have the same parameter and include the same header file. The line where the parameter is repeated (to be used for an operation) is the one with " undefined reference" - even though the parameter is declared in the header and has the implementation in the .c file above.

As I said before this problem occurs with fourteen parameters split between four .c files. The implementations are in two of the.c files (four in one and ten in the other) and all the errors are in the other two .c files (two in one and fifteen in the other)

I can force Code::Blocks to compile and link in a defined order, but repeated changes of order, based on what I thought best, have made no difference.

Finston

Problem solved - I think. Some of my .c files seem to have complied as c++. My header file gave appropriate declarations which were not picked up on linking the .o files from my "true".c files.

Perhaps someone can describe this better!

Happy Finston

Perhaps someone can describe this better!

C++ performs name mangling to enable the overloading feature. If you declared the entities with C linkage (by compiling them as C) and tried to link with the same entities that have C++ linkage (by compiling them as C++), there won't be a match due to mangling. So while the names would be declared, and appear to be defined in the source code, they wouldn't actually be defined.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.