Click here to Skip to main content
Click here to Skip to main content

Link order and mixed-mode DLLs

, 26 Jan 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
When linking a mixture of mixed-mode and unmanaged DLLs to an unmanaged C++ executable, the link order can affect how the program runs.
I recently added a mixed-mode C++/CLI DLL to an existing unmanaged C++ project which also included two unmanaged C++ DLLs, and found that the application file would crash very early on, before it had even reached any user code.
 
After pulling out what little remains of my hair, I found that the order the DLLs' .lib files are linked to the executable affects whether or not it will crash.
 
Basically, if you have an unmanaged and a mixed-mode DLL linked to the same executable, the mixed-mode DLL's .lib file must be linked first, or the application will crash.
 
Just a short tip, but hopefully it'll be useful to someone!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

viaducting
Software Developer
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
GeneralThis is new fact to me. Did you got the reason why it is beh... PinmemberLakamraju Raghuram26-Jan-12 5:31 
GeneralRe: It might be because the link order affects the order in whic... Pinmemberviaducting26-Jan-12 5:41 
It might be because the link order affects the order in which the DLLs are initialised, and the mixed-mode DLLs have to be initialised first, but I don't know for certain if that is the reason.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 26 Jan 2012
Article Copyright 2012 by viaducting
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid