This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi, I'm just starting out in CCS. I've got the project set up, have a main.c which calls a single function, InitHardware();.
I have a file called Init_Hardware.cpp that defines void InitHardware(void);
And a file called Init_Hardware.cpp that has the code for void InitHardware(void) { P1DIR = 0x00;};
main.c does include Init_Hardware.hpp as the linker map verifies this
When I build this I get an undefined symbol error.
undefined first referenced
symbol in file
--------- ----------------
InitHardware ./main.obj
For the life of me I can't figure out why. Any help would be appreciated and any insult about my programming prowess would be accepted..
Thanks!
Rich
Rich,
When mixing C and C++ code, use the C linkage convention (extern "C") on your C++ function declarations.
More details are in this wiki page: http://processors.wiki.ti.com/index.php/Overview_of_C%2B%2B_Support_in_TI_Compilers#Name_Mangling
Thanks for the reply - in my header file, entire file below, I did try an extern declaration, but I got an error message #41 - expected an identifier. And the build stops without linking.
The commented out code with no extern didn't return an error here, but it did give the unresolved symbol message, which I understand now from your post..
//
/// Init_Hardware.hpp Header file
//
//////////////////////////////////////
//
//
//void InitHardware(void);
extern "C" void InitHardware(void);
//
Is there something wrong in the extern declaration, does the code also need the extern? - though I did try that.
-Rich
Thanks! It worked great. I wasn't aware that the __cplusplus definition could and should be used at this point. I appreciate your time!
-Rich
Hi Aarti,
I am trying to interface C with ASM as described at page 132 of ARM compiler SPNU151G.
Taking the given C and ASM code of page 132 I am getting the same error with comparable syntax (but for different prupose):
extern "C" {
extern int asmfunc(int a); /* declare external asm function */
int gvar = 0; /* define global variable */
}
**** Build of configuration Debug for project AM335x_basic ****
/home/sitara/ti/ccsv5/utils/bin/gmake -k all
Building file: ../hello.c
Invoking: ARM Compiler
"/home/sitara/ti/ccsv5/tools/compiler/tms470/bin/cl470" -mv7A8 --code_state=32 --abi=eabi -me -g --include_path="/home/sitara/ti/ccsv5/tools/compiler/tms470/include" --diag_warning=225 --display_error_number --preproc_with_compile --preproc_dependency="hello.pp" "../hello.c"
"../hello.c", line 7: error #41: expected an identifier
>> Compilation failure
"../hello.c", line 7: error #66: expected a ";"
where line 7 is extern "C" {.
Is there a know issue to interface ASM and C in CGTools 4.9.1 with CCS 5.1.1.00033?
Or are there specific compiler options that are needed for this?
Thanks in advance and best regards,
Anthony
extern "C" is not legal C code, it is C++ code. You must do this in a header file which is shared between C and C++ modules:
#ifdef __cplusplus extern "C" { #endif extern int asmfunc(int a); /* declare external asm function */ int gvar = 0; /* define global variable */ #ifdef __cplusplus } #endif
[Edit: should be ifdef, not ifndef --Archaeologist]