Order of -ladvapi32 versus -lkernel32

40 views
Skip to first unread message

vitaly.kru...@gmail.com

unread,
Mar 17, 2016, 5:57:33 PM3/17/16
to mingwpy
My project's CMAKE_CXX_STANDARD_LIBRARIES originally contained by default: "-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32" (without the quotes).

I used mingwpy running on Windows Server 2008 32-bit to build my python extension DLL. The apr (apache portable runtime) library that's linked as a static library into my extension DLL makes a call to "CreateProcessAsUserW". When testing, I would get this error: "The procedure entry point CreateProcessAsUserW could not be located in the dynamic link library KERNEL32.dll". I found this error surprising, because CreateProcessAsUserW is in advapi32, and "-ladvapi32" was listed at the end of CMAKE_CXX_STANDARD_LIBRARIES, so it should have been picked up by mingwpy's linker/loader. I was able to fix this failure by moving 
"-ladvapi32" to the beginning so that it was in front of "-lkernel32" like so: "-ladvapi32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32".

However, I don't understand why it was necessary to place -ladvapi32 in front of -lkernel32 to make the CreateProcessAsUserW problem go away. Does someone know why this would be necessary?

Many thanks,
Vitaly

Carl Kleffner

unread,
Mar 17, 2016, 6:32:23 PM3/17/16
to min...@googlegroups.com
This is more a question for a gcc or mingw-w64 mailing list.

The order of the libraries in the link command matters and depends how the DLLs are depend on each other. Estimate the correct order by trial and error is sometimes the best approach.

--
You received this message because you are subscribed to the Google Groups "mingwpy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mingwpy+u...@googlegroups.com.
To post to this group, send email to min...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mingwpy/ccf1b280-522f-4489-a73d-8fbb05928fb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nathaniel Smith

unread,
Mar 17, 2016, 6:35:29 PM3/17/16
to mingwpy
You might also want to look into the --start-group / --end-group flags to ld:
https://stackoverflow.com/questions/5651869/gcc-what-are-the-start-group-and-end-group-command-line-options
> --
> You received this message because you are subscribed to the Google Groups
> "mingwpy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mingwpy+u...@googlegroups.com.
> To post to this group, send email to min...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mingwpy/ccf1b280-522f-4489-a73d-8fbb05928fb2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
Nathaniel J. Smith -- https://vorpus.org

vitaly.kru...@gmail.com

unread,
Mar 17, 2016, 9:49:48 PM3/17/16
to mingwpy
Thank you. I posted this question on the mingw-w64-public mailing list.
Reply all
Reply to author
Forward
0 new messages