Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 11:19 Go to next message
Kristinn  is currently offline Kristinn Friend
Messages: 5
Registered: June 2011
Junior Member
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 10:12 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Looks like foo.c is not linked against main.cpp. What kind of project did you setup in Eclipse?

Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: header and source files? [message #690897 is a reply to message #690284] Thu, 30 June 2011 11:52 Go to previous messageGo to next message
Kristinn  is currently offline Kristinn Friend
Messages: 5
Registered: June 2011
Junior Member
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 11:58 Go to previous messageGo to next message
Kristinn  is currently offline Kristinn Friend
Messages: 5
Registered: June 2011
Junior Member
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 13:54 Go to previous messageGo to next message
Kristinn  is currently offline Kristinn Friend
Messages: 5
Registered: June 2011
Junior Member
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 14:18 Go to previous messageGo to next message
Kristinn  is currently offline Kristinn Friend
Messages: 5
Registered: June 2011
Junior Member
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 08:57 Go to previous message
a11649635 is currently offline a11649635Friend
Messages: 1
Registered: November 2011
Junior Member
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: Sat Apr 20 12:52:24 GMT 2024

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

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

Back to the top