Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » header and source files?(header file source file noninteraction)
header and source files? [message #689790] Tue, 28 June 2011 07:19 Go to next message
Eclipse UserFriend
Hello, great CDT gurus.

I humbly come here requesting help with a problem I´ve been having and having scanned through the forums havent found a solution to yet (or maybe I am too dense to spot it).

Let us consider the following scenario.
I have foo.h and foo.c files. foo.h contains the prototype for "void HungFoo(int n);" and its code is in the .c file. Now I include foo.h in my main.cpp file and try to use the HungFoo function. When I build the project I am greeted with a "undefined reference to 'HungFoo'" error. Is there a fix to this? Or does eclipse just not support indirect referencing like this between a .h and .c (or .cpp) file?

I used this quite a lot in visual c++ which makes me wonder if this is a missing functionality or if I missed a step somewhere?
Re: header and source files? [message #690284 is a reply to message #689790] Wed, 29 June 2011 06:12 Go to previous messageGo to next message
Eclipse UserFriend
Looks like foo.c is not linked against main.cpp. What kind of project did you setup in Eclipse?
Re: header and source files? [message #690897 is a reply to message #690284] Thu, 30 June 2011 07:52 Go to previous messageGo to next message
Eclipse UserFriend
I started a c++ project, how would I go about linking the foo.c to main.c?
Re: header and source files? [message #690903 is a reply to message #690897] Thu, 30 June 2011 07:58 Go to previous messageGo to next message
Eclipse UserFriend
Tought it might be useful adding the actual compiler/linker output from my current project, obviously its not a foo.something type project Smile :
Quote:

Building target: FunkOS_Test.elf
Invoking: AVR C++ Linker
avr-gcc --cref -s -Os -o "FunkOS_Test.elf" ./driver.o ./heap.o ./kernelswi.o ./kerneltimer.o ./kernelwdt.o ./main.o ./message.o ./mutex.o ./semaphore.o ./task.o ./taskport.o ./timer.o ./watchdog.o -lArduinoCore -lm -Wl,-Map,FunkOS_Test.map,--cref -L"C:\Users\kristinnes\workspace\ArduinoCore\Release" -mmcu=atmega328p
./main.o: In function `MyTask(MY_TASK_STRUCT*)':
../main.cpp:85: undefined reference to `Task_Sleep(unsigned short)'
./main.o: In function `main':
../main.cpp:44: undefined reference to `Task_Init()'
../main.cpp:52: undefined reference to `Task_CreateTask(Task_Struct*, char*, unsigned char*, unsigned short, unsigned char, void (*)(void*))'
../main.cpp:60: undefined reference to `Task_CreateTask(Task_Struct*, char*, unsigned char*, unsigned short, unsigned char, void (*)(void*))'
../main.cpp:62: undefined reference to `Task_Add(Task_Struct*)'
../main.cpp:63: undefined reference to `Task_Add(Task_Struct*)'
../main.cpp:65: undefined reference to `Task_Start(Task_Struct*)'
../main.cpp:66: undefined reference to `Task_Start(Task_Struct*)'
../main.cpp:68: undefined reference to `Task_StartTasks()'
make: *** [FunkOS_Test.elf] Error 1

Re: header and source files? [message #690983 is a reply to message #690903] Thu, 30 June 2011 09:54 Go to previous messageGo to next message
Eclipse UserFriend
Ok update.. The code compiles but only if I change the ending of main.cpp to main.c Razz I did start this as a c++ project.. what am I doing wrong? I´d like to use c++ code to work with this.
Re: header and source files? [message #690997 is a reply to message #690983] Thu, 30 June 2011 10:18 Go to previous messageGo to next message
Eclipse UserFriend
I am an idiot. I know the problem Smile No need pointing out he obvious, hehe
Re: header and source files? [message #757562 is a reply to message #690997] Sat, 19 November 2011 03:57 Go to previous message
Eclipse UserFriend
Can you please "point out the obvious" to the reset of us?
I think I'm experiencing the same problem as you (cpp files with .h files and undefined reference)
thanks
Previous Topic:problems with linking libraries
Next Topic:Remote connection closed after "list-thread-groups"
Goto Forum:
  


Current Time: Wed Jul 09 15:43:20 EDT 2025

Powered by FUDForum. Page generated in 0.07562 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top