Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Solving linker warning 1

Status
Not open for further replies.

BoMi

Programmer
Jul 20, 2006
39
RS
Hi!
I'm a very beginner C++ Builder programmer. So, I guess my question will be simple for you guys here.

I've been developing a simple application with two forms: one main and one modal (or even non modal). Adequate files are: main.cpp and modal.cpp.
I call and show modal form from main form.

I would like to know this:

- in order to use modal (or non modal) form from main form, I must do #include "modal.cpp" in main.cpp (or maybe in main.h???), correct or not?

- if previous is correct (and I guess it is) then does it matter where I include modal.cpp: in main.cpp or main.h?

- when I include modal.cpp in main.cpp and build the application, I get this linker warning:

Public symbol '_modal' defined in both module: (here goes the location of created main.obj) and (here goes the location of created modal.obj)

Now, my application works perfectly, but I would like to get rid of this warning, it is really annoying to me.
I tried to turn off this linker warning, but it doesn't seem to be possible to do that for this warning.
Is there a solution(s) for this 'problem'?

I've been using C++ Builder 5 to develop this application, but I also have C++ Builder 2006 installed, and it gives me the same warning message.

I would appreciate any answer. Thank you in advance...

BoMi
 
To access the Modal form (which is declared in modal.h) from main.cpp, you have to specify "#include modal.h" in main.cpp, so that the compiler will not throw an error when you refer to ModalForm in main.cpp. If instead you include modal.cpp in main.cpp, then you are duplicating the form's code, which would result in an error like the one you describe.
 
Thank you very much TonyGroves.

That was a really stupid question of mine. I thought I tried that...

But, now, I have a similar problem.

Let's say I declared a global variable in modal.cpp (or modal.h) and I use that variable in main.cpp, how should I do that #include stuff in order to avoid this same warning (but now for variable I declared in modal.cpp)?

I'll appreciate any answer. Thank you in advance...

P.S.
I know this is kind of boring and stupid, but I'm a bit confused and it seems I can't figure it out how to solve it.
So, thank you for being so kind to answer this...
 
If you declare a variable in modal.cpp, something like "int abcde;", you can then put "extern int abcde;" into main.cpp, and the linker will match that to the original declaration.
 
Thank you very much again TonyGroves.

That solved my problem.
I remember now that I used extern static, ... in C here and there, but I forgot about that.
Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top