Getting started with Crossworks: Linker error

I’m just getting started with my first Crossworks project using a Luminary LM3S601 Cortex MCU and I’d like help with what is probably a basic problem:

My two C files both compile fine but at linking time my main.c file has the error:

/Debug/main.o: in function ‘main’:

undefined reference to ‘SysCtlClockSet’

Which is a function in my only other source file: sysctl.c which is located in a different directory to the project and main.c .

Even though I have both main.c and sysctl.c in my project and I’ve got the line " #include <sysctl.h> " in main.c it appears the linker can’t link the two object files. Tia for any suggestions to fix this as I’ve been Googling and reading the help files with no success so far.

What is the exact linker command that causes this error?

I’m not familiar with Crossworks, but in general it can help to re-order the object files for the linker.

Are you using C++ in your project?

When you combine C and C++ in a project, you have to be aware of the difference between the way that symbols are named in object files. C++ ‘mangles’ the names by adding some kind of encoding for the parameters (C++ allows functions to have the same name but different parameters).

Prof_Hikita:
I’m just getting started with my first Crossworks project using a Luminary LM3S601 Cortex MCU and I’d like help with what is probably a basic problem:

My two C files both compile fine but at linking time my main.c file has the error:

/Debug/main.o: in function ‘main’:

undefined reference to ‘SysCtlClockSet’

Which is a function in my only other source file: sysctl.c which is located in a different directory to the project and main.c .

Even though I have both main.c and sysctl.c in my project and I’ve got the line " #include <sysctl.h> " in main.c it appears the linker can’t link the two object files. Tia for any suggestions to fix this as I’ve been Googling and reading the help files with no success so far.

I may be way off base here, being more of a hardware guy and just a software twidler. But, I thought that the <file.h> notation was for headers in the compiler’s standard library, and that you needed to use “file.h” notation to refer to a header file in you own project? If that is all it is, then the compiler probably is not finding the header file for your sysctl.c file?

–Dave

bertrik:
What is the exact linker command that causes this error?

I’m not familiar with Crossworks, but in general it can help to re-order the object files for the linker.

Are you using C++ in your project?

When you combine C and C++ in a project, you have to be aware of the difference between the way that symbols are named in object files. C++ ‘mangles’ the names by adding some kind of encoding for the parameters (C++ allows functions to have the same name but different parameters).

Hi Bertrik: there’s no C++ and all C source files in the project end in “.c”. I ran the build command again and it did compile main.c before sysctl.c, I’ll try and reorder the linking and see how that goes.

Rebuild active project

Rebuilding “glubba” in configuration “THUMB Flash Debug”

Compiling main.c

Compiling sysctl.c

Assembling thumb_crt0.s

Assembling LM3S_Startup.s

Generating linker script

Linking glubba.elf

THUMB Flash Debug/main.o: In function `main’:

C:/Program Files/Rowley Associates Limited/CrossWorks for ARM 1.7/Projects/glubba/main.c:12: undefined reference to `SysCtlClockSet’

Build failed

dshuman:

Prof_Hikita:
I’m just getting started with my first Crossworks project using a Luminary LM3S601 Cortex MCU and I’d like help with what is probably a basic problem:

My two C files both compile fine but at linking time my main.c file has the error:

/Debug/main.o: in function ‘main’:

undefined reference to ‘SysCtlClockSet’

Which is a function in my only other source file: sysctl.c which is located in a different directory to the project and main.c .

Even though I have both main.c and sysctl.c in my project and I’ve got the line " #include <sysctl.h> " in main.c it appears the linker can’t link the two object files. Tia for any suggestions to fix this as I’ve been Googling and reading the help files with no success so far.

I may be way off base here, being more of a hardware guy and just a software twidler. But, I thought that the <file.h> notation was for headers in the compiler’s standard library, and that you needed to use “file.h” notation to refer to a header file in you own project? If that is all it is, then the compiler probably is not finding the header file for your sysctl.c file?

–Dave

Hi Dave, I’m probably about 60% a hardware guy and 40% a software guy myself. My entire main.c is listed below, I know the sysctl.h header file is being included ok in main.c as once it’s commented out I have extra compile errors due to values such as “sys_use_osc” being #define in sysctl.h. main.c will compile and so does sysctl.c, both files have #include for sysctl.h and it all falls over at link time from what I can see of the error messages (see reply to Bertriks post for the error).

#include <hw_types.h>

#include <hw_gpio.h>

#include <hw_memmap.h>

#include <hw_sysctl.h>

#include <sysctl.h>

int main (void)

{

SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

return 0;

}

Prof_Hikita:
Hi Dave, I’m probably about 60% a hardware guy and 40% a software guy myself. My entire main.c is listed below, I know the sysctl.h header file is being included ok in main.c as once it’s commented out I have extra compile errors due to values such as “sys_use_osc” being #define in sysctl.h. main.c will compile and so does sysctl.c, both files have #include for sysctl.h and it all falls over at link time from what I can see of the error messages (see reply to Bertriks post for the error).

#include <hw_types.h>

#include <hw_gpio.h>

#include <hw_memmap.h>

#include <hw_sysctl.h>

#include <sysctl.h>

int main (void)

{

SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

return 0;

}

I see what you mean. It seems that the the constant definitions are being found in “sysctl.h”, but for some reason the prototype for “SysCtlClockSet()” is not being found in “sysctl.h”? Maybe some of the software experts here can figure out how that can happen?

–Dave

If you look in the source you will see the functions have a #if defined statement around them.

you will need to do the following.

add BUILD_ALL and gcc to the preprocessor defines

add cpu.S, interrupt.c aswell as sysctl.c to your project

add the following to your main for example (only required for debug build)

#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

One thing rowley prebuild the lib, you could just link with libdriver.a

Have a look at the provided examples for more details.

Cheers

Spen

ntfreak:
If you look in the source you will see the functions have a #if defined statement around them.

you will need to do the following.

add BUILD_ALL and gcc to the preprocessor defines

add cpu.S, interrupt.c aswell as sysctl.c to your project

add the following to your main for example (only required for debug build)

#ifdef DEBUG

void
error(char *pcFilename, unsigned long ulLine)
{
}
#endif



One thing rowley prebuild the lib, you could just link with libdriver.a

Have a look at the provided examples for more details.



Cheers

Spen

Thanks Spen: I added “BUILD_ALL” and “gcc” to my solution “preprocessor definitions” and followed your instructions and now the project builds fine. Thankyou