Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / MFC
Tip/Trick

Link order and mixed-mode DLLs

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
26 Jan 2012CPOL 18.5K   3   2
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)


Written By
Software Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralThis is new fact to me. Did you got the reason why it is beh... Pin
Lakamraju Raghuram26-Jan-12 4:31
Lakamraju Raghuram26-Jan-12 4:31 
GeneralRe: It might be because the link order affects the order in whic... Pin
hairy_hats26-Jan-12 4:41
hairy_hats26-Jan-12 4:41 

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

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