* newbie question on linking classes
@ 2008-03-27 16:11 Koyel Mukherjee
2008-03-27 16:40 ` John Love-Jensen
0 siblings, 1 reply; 3+ messages in thread
From: Koyel Mukherjee @ 2008-03-27 16:11 UTC (permalink / raw)
To: gcc-help
Hi
I am a newbie on using gcc and linking files. I have defined some
classes (.h and .cpp files) which I want to use in my main function
defined in a source file(containing the main() function. I have kept
all the class files (.h and .cpp) along with the .cpp source file in
one directory. When I compile only using :
g++ source.cpp
it compiles fine. However, when I try to link it too, by writing:
g++ source.cpp -o source_e
I get a series of errors containing
: undefined reference to func (say) where func is say, a function I
have declared in one of my class files. It seems that it is not able
to link properly . I have included the header files of the classes in
the source file. However I am still getting this error. I tried
specifying the directory where all these files are by the -B option
but it did not help either. Please help me out!
Thanks a lot.
Regards
Koyel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: newbie question on linking classes
2008-03-27 16:11 newbie question on linking classes Koyel Mukherjee
@ 2008-03-27 16:40 ` John Love-Jensen
2008-03-27 19:25 ` Koyel Mukherjee
0 siblings, 1 reply; 3+ messages in thread
From: John Love-Jensen @ 2008-03-27 16:40 UTC (permalink / raw)
To: Koyel Mukherjee, GCC-help
Hi Koyel,
You are compiling and linking source.cpp.
You need to compile and link all your source code.
e.g.
g++ source.cpp uno.cpp dos.cpp tres.cpp -o myapp
If you do your compiling separate from your linking:
g++ source.o uno.o dos.o tres.o -o myapp
HTH,
--Eljay
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: newbie question on linking classes
2008-03-27 16:40 ` John Love-Jensen
@ 2008-03-27 19:25 ` Koyel Mukherjee
0 siblings, 0 replies; 3+ messages in thread
From: Koyel Mukherjee @ 2008-03-27 19:25 UTC (permalink / raw)
To: John Love-Jensen; +Cc: GCC-help
Hi John
Thanks a lot! My code has compiled and linked perfectly now!
Regards
Koyel
On Thu, Mar 27, 2008 at 11:39 AM, John Love-Jensen <eljay@adobe.com> wrote:
> Hi Koyel,
>
> You are compiling and linking source.cpp.
>
> You need to compile and link all your source code.
>
> e.g.
> g++ source.cpp uno.cpp dos.cpp tres.cpp -o myapp
>
> If you do your compiling separate from your linking:
> g++ source.o uno.o dos.o tres.o -o myapp
>
> HTH,
> --Eljay
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-03-27 19:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-27 16:11 newbie question on linking classes Koyel Mukherjee
2008-03-27 16:40 ` John Love-Jensen
2008-03-27 19:25 ` Koyel Mukherjee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).