Gentlefolk,

Totally new to the world of C C++, compilers and linkers.

I am attempting to compile and build some demonstration application code which access BlueTooth devices.

Have all the .C, .H files, also a .lib.

Using the LCC c ide-compiler-linker, etc on Windows-32

Compile one module - no errors.
Link the module and get a raft of undefined errors, an example:

"undefined reference to '_fred' "

'Fred' is defined in the .c file as "void Fred(void);".

I have done some research and for historical reasons some C type compilers prepend underscores to "external" symbols.

An inspection of the provided .lib file shows a number of "_Fred" symbols, unfortunately I do not have a definition of the .lib file structure to work out if things are OK. The .lib file is accessed during the link process. "Fred" and "_Fred" do not appear in a .map file.

My problem is I cannot find out how to get the linker to resolve this undefined, or perhaps stop the compiler generating such a symbol.

Any thoughts, ideas or directions appreciated.

iru, Melbourne, Australia.

Recommended Answers

All 7 Replies

'Fred' is defined in the .c file as "void Fred(void);".

That's just a prototype. The function actually needs to be defined somewhere, or else the linker will complain (as you see). A function needs to exist if it is going to be called. This non-existent function of course will not be found in a map file either.

My problem is I cannot find out how to get the linker to resolve this undefined, or perhaps stop the compiler generating such a symbol.

Define the function?

void Fred(void)
{
   /* ... */
}

Thanks, for the response, it helped.

I chased up a copy of "The C programming language" by Kernighan and Ritchie. C has changed/developed since that was written as "prototype" does not get a mention. I think my problem is not so much with the C language but the environment around it.

I understand the suggestion to define the "Fred" function. However what if I want to access a pre-defined function? In the application code the function GetASerialCon is defined in a xx_API.h file as "BUINT32 GetASerialCon()" and causes a similar error to "Fred", undefined reference to _GetASerialCon.

I presume that _/GetASerialCon is a routine in the supplied .DLL file and is accessed by an entry point, offset or whatever into the DLL.

I should be able to inform the linker that GetASerialCon does exist and is available in the DLL. I thought the supplied library .LIB file would do this (it does contain the string GetASerialCon).

I have chased around the Internet for further information but no luck, I have not been able to find a coherent (to me anyway) explanation of the "C" linking process.

Any thoughts, explanations, directions??

Thanks, iru.

http://en.wikipedia.org/wiki/Library_(computing)

How stuff gets linked would be up to the tools you are using to build, and are not something you'd really find in the language definition. That is, the implementation will describe its specifics.

[edit]I'm not sure what you're looking for with your GetASerialCon example. Maybe less paraphrasing ("xx_API.h") and a more concrete example would help.

I have progressed somewhat, I think.

I have found that the tools I was attempting to use had problems with periods "." in directory-file paths (supplied with application code).
Simplified director-file paths and things went a lot better.

Different "C" compilers (and different config options) resulted in different errors and apparently different tpes of .obj files.
Fought my way through that lot and came up with consistent errors.

All work was done outside an IDE, separate compiler and linker.

Could compile the main .C file clean with no errors. Worked out what other .C and .H files were required. Linked them and resolved any inter-module function reference errors.
All that is left is a number of unresolved errors when linking.

As an example:

The main program file sdk_tst.c utilises the function bsdk_init - if (BTSDK_OK == Btsdk_Init()).
Btsdk_Init is defined as BTINT32 Btsdk_Init(void); in the file btsdk_API.h which is included in sdk_tst.c and .h.

Compiles clean but BTINT32 Btsdk_Init(void) is a prototype definition only.
Linking I get a missing reference on _Btsdk_Init. This is reasonable as Btsdk_Init is a prototype not code.

There is static linking and dynamic linking (about 4 sub-types). None of the documentation on the linkers I have used explains much about how they operate and what they produce.

The documentation with the application specifies that the bluetooth devices (BT)sdk..... are accessed via a bssdk.dll file they supply.

Therefore to me it looks like the linker should relate _Btsdk_Init to some pointer/entry point/offset into the .dll.

Where could the linker get this information?? A library file is provided (bssdk.lib) the documentation specifies this .lib is the API function address library linking wite developers program.
A look through the mixture of ascii and hex in this file shows the ascii string _Btsdk_Init and a nearby ascii string BsSDK.dll the name of the supplied .dll.
Tried adding/including the .lib file in the linker in a number of ways, no improvement.

It looks like my problem is coming down to getting a linker to successfully process the .obj files and the .lib file and produce an .exe.
According to the documentation MS Visual C++ 6.0 was used to build the application. Looks like it's linker and library fit together.

More work to be done..... IRU.

I seem to have exhausted what I can do with the LCC linker, all .obj clean but cannot link. Cannot import/integrate the supplied .lib file. No documentation about the characteristics/capabilities of the linker.

Tried using Borland's Turbo C++ as there are interesting options in the linker and library config.

Woops no win.h. Use the one from LCC he thinks, ugly syntax errors, try different source types (config option (Unic, TurboC...)), win.H is processed correctly. Woops ugly syntax in stdarg.h (included in win.h), do not mix LCC and Turbo C++!!!!

Currently failing with ugly syntax errors in stdio (from LCC).

I am sure this is character building but I am not getting any nearer to getting a clean executable.

Seasons greetings, iru.

I downloaded, installed and created a test console program. Interesting looking C compiler (it is not a c++ compiler too).

Gentlefolk,

I attempted to reply earlier but have been stuck in some sort of a login-loop, finally out of it.

After thinking about things for a bit I considered that I needed to try the MS Visual C++ path. Where to get the Visual C++??, Finally realised I could access it via one of my sons.

Built a new virtual system, loaded Visual Studio.

Opened the project file supplied with the demonstration application I am attempting to use. Complaints about version and would I accept a conversion? Yes I answered and suddenly I had a file tree structure in a window on the GUI. On inspection it looked OK.

Compiled the code, a squillion warnings about deprecated functions but no errors and on the bottom line it said an executable had been created.

Executed the executable and the program ran and I could talk BlueTooth to my phone.

So all this trouble was caused by not having the right combination of .H, .C, .LIB and C++ compiler and Linker.....................

Thanks for all assistance, iru.

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.