|
I'm trying to put reusable code into a static library and link it into a couple of different projects.
The problem is that while linking one of the projects that's supposed to use the reusable code, it reports all sorts of multiply defined symbols. (See below)
The main projects use DLL versions of the C-runtime, and the static library is set to use the multi-threaded dll version also.
What's the trick to successfully linking a static library into multiple projects?
(If I haven't provided enough info, just ask.)
Multiply defined symbols messages:
(Is this happening because the C-runtime is linked into the static lib first, and then those symbols are conflicting with the symbols in the main project?)
5>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __CrtSetCheckCount already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __calloc_dbg already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(sprintf.obj) : error LNK2005: _sprintf already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __cexit already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(wsetloca.obj) : error LNK2005: __configthreadlocale already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(swprintf.obj) : error LNK2005: _swprintf_s already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(mlock.obj) : error LNK2005: __lock already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(mlock.obj) : error LNK2005: __unlock already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(winapisupp.obj) : error LNK2005: ___crtGetShowWindowMode already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(winapisupp.obj) : error LNK2005: ___crtSetUnhandledExceptionFilter already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(winapisupp.obj) : error LNK2005: ___crtTerminateProcess already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(winapisupp.obj) : error LNK2005: ___crtUnhandledException already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(vsnprnc.obj) : error LNK2005: __vsnprintf_s already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
5>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
5>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
5>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
5>LIBCMTD.lib(vswprnc.obj) : error LNK2005: __vsnwprintf_s already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(dbgrptw.obj) : error LNK2005: __CrtDbgReportW already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(printf.obj) : error LNK2005: _printf already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in msvcrtd.lib(MSVCR120D.dll)
5>LIBCMTD.lib(towlower.obj) : error LNK2005: _towlower already defined in msvcrtd.lib(MSVCR120D.dll)
5>LINK : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
5>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
This looks like you're mixing C runtime library types, double check your settings and make sure they're the same. MS really makes it a pain to use libraries that support different projects (that may have multiple runtimes). Essentially you're supposed to make a lib build compatible with each runtime available and link up your main project to the right one.
|
|
|
|
|
Thank you, you are correct. It turns out that it had to do with a third-party library that I was also linking in. I was linking in the version that used the static C library instead of the shared.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Glad you found the cause...
|
|
|
|
|
Add the option '-verbose ' to the linker. It will tell you exactly why it pulls in which lib.
Maybe also add '-nodefaultlib:libcmtd.lib ' to force 'link' not to pull in
libcmtd.lib<code>.<br />
<div class="signature">Gisle V. <br />
<br><small><tt># rm -vf /bin/laden<br />
/bin/rm: success</tt></small><br></div>
|
|
|
|
|
The objective is to create a class that contains the methods to create and gather messages from a series of message dialogs by means of a series of buttons on a dialog created with the resource editor.
The app is being written with VS 2010 and the classes, events etc. utilizing the supplied Wizards. This is an SDI app with p_MFCls-> pointing to the MainFrameEx* object and p->MsgCls being the child of p_MFCls-> and a CWnd* object. p_Dlg-> is a pointer to the actual dialog box and is a CDialog* object parented by the p_MsgCls object.
FWIW: Windows 8.1
I have the following code (partial):
In p_MFCls:
//.h
CJBK_Msg* p_MsgCls;
//.cpp
p_MsgCls = new CJBK_Msg;
ASSERT(p_MsgCls->Create(NULL, NULL, 0, CRect(0, 0, 0, 0), this, IDCls_Msg));
In p_MsgCls, when the appropriate message is received, we have:
CDialog* p_DlgBox;
<pre lang="cs">p_DlgBox = new CDialog;
ASSERT(p_DlgBox->Create(p_strMsgBox->nDlgBoxResID, this));
For the button(s), I used the Event Handler Wizard but whether I tell it to send the event to p_MFCls or p_MsgCls, it never gets there when I click the button control.
Can anyone spot something that I have missed?
Thanks and Happy Holidays to all,
Barry
|
|
|
|
|
BarryPearlman wrote: Can anyone spot something that I have missed? Where is the actual event handling code? What you have shown above does not tell us anything about where these events are supposed to be captured.
Veni, vidi, abiit domum
|
|
|
|
|
Sorry about that! Ideally the button click event should be handled first in p_MsgCls since p_MsgCls-> is intended to handle all of the messages for the entire application. Second choice is CMainFrameEx.
Using the Event Handler Wizard for p_MsgCls I get:
//.h
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClicked_MB_Btn2();
//.cpp
BEGIN_MESSAGE_MAP(CJBK_Msg, CWnd)
..........................
ON_BN_CLICKED(ID_MB_Btn_2, &CJBK_Msg::OnBnClicked_MB_Btn2)
END_MESSAGE_MAP()
void CJBK_Msg::OnBnClicked_MB_Btn2()
{
}
I am working under the assumption that if the Event Handler Wizard (in general) presents me with a choice, it is a valid one and will work.
Thanks,
Barry
|
|
|
|
|
BarryPearlman wrote: I am working under the assumption Never do that, check everything. However good the wizards may be they are not infallible. You can easily check that things are plugged together correctly by setting a few breakpoints in your code and running some controlled tests.
Veni, vidi, abiit domum
|
|
|
|
|
I always do. That is how I found out that the code that the Event Wizard Handler was writing code that wasn't working in the first place. The question still remains why can't I get the event to fire in p_MSCls->?
Thanks,
Barry
|
|
|
|
|
Does the control that raises the event belong to this class, and are the message macros pointing to the right places? From the little pieces of code you have shown us it is not easy to understand how your project fits together.
Veni, vidi, abiit domum
|
|
|
|
|
You may be on the right class concerning who belongs to which class and hence the missing events. I will get back to this project later on in the week and thanks to you have some new avenues to explore.
Thanks & Happy Holidays,
Barry
|
|
|
|
|
You have wrapped the Create() functions in ASSERT() macros, which at least in Visual Studio 6.0 means they are executed only in debug mode. Assuming this behavior has not changed in VS 2010, you should use VERIFY() instead.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
This post dealt with missing events, not a request for the difference between ASSERT() and VERIFY()! Frankly, I am hard pressed to find a decent explanation of the fine nuances between them, except their use during runtime and debug.
It is my own personal philosophy that the end user should never see the arcane messages these macros produce. An error at a hex address means absolutely nothing to a user except that there is an error and that the developer has failed to take something into account.
Perhaps a philosophical dissertation/lecture is in order here??
|
|
|
|
|
This wasn't meant as a philosophical discussion. If you enclose an important function call, e.g. the creation of a dialog in an ASSERT(), the dialog will not be created in Release mode and therefore can't receive any messages.
If you use VERIFY(), the dialog will be created in Release mode as well. However, the "arcance message" as you call it, will only be displayed in Debug mode.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
I'm doing project on morse code translator in Cpp Im unable to write it?? plz help ....
|
|
|
|
|
Help with what? Please don't expect people here to do your work for you.
Veni, vidi, abiit domum
|
|
|
|
|
Dhananjay RajeNimbalkar wrote: plz help ....
Steps:
1. Learn the basics of C++.
2. Presumably you are going to do this from the command line so learn how to accept input and write output to the console in C++.
3. Learn how to parse a string (input)
4. Learn how arrays work.
5. Find source for a morse code map.
6. Put all of the above together to make your application.
|
|
|
|
|
Read and heed here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I did one of those many years ago. Since everyone's morse-code sending speed is a little different, you have to take this into account.
For a morse-code message you have pulses of different lengths. Sort the pulses by duration. Then look for the biggest gap between durations: This is the threshold between a "dot" and a "dash".
Now you can translate the pulses into dots and dashes, and the rest is just programming technique.
|
|
|
|
|
Hello everybody,
I am in project with win32.
I am using OPENFILENAME structure for selecting a file (GetOpenFileName()).
Problem is, it is possible to delete a file in browse dialog, which will create some issues.
is there any way to prevent deleting the files in browse dialog?
Regards,
A. Gopinath.
|
|
|
|
|
In order to have full control, you might implement the hook procedure.
Veni, vidi, vici.
|
|
|
|
|
This comes to mind.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I'm working with a MFC program based on DHTMLDialog in visual studio 2010, one problem is that sometimes IME is disabled in my program, which means I can only input English(no chinese) in it, another is that sometimes chinese can be input but the IME candidate window don't appear.( )
one cause of the first problem found is that flash disabled IME of the program via some C api.
How can I repair it? I try to use WINNLSEnableIME but seems to be no effective
Regards,
buaaxiao
modified 5-Dec-13 7:37am.
|
|
|
|