Static compilation and use in a DLL compatible with rundll32
Date: Wed, 6 May 2020 15:51:17 +0200
Hello,
First message for this mailist, many thanks for your help and time guys.
I am trying to crosscompile an statically version of libcurl which can
be use by mingw to create a DLL usable by rundll32 on a Windows
system.
I am trying this from an Ubuntu 18.04.4 LTS with the current git
version of libcurl which is 7.70.1-DEV and I am executing the library
with: rundll32.exe "<PathToDLL>",AltEntry
I also verified that the exported function is present through a small
windows tool called dllexp.exe.
Unfortunately, when including the libcurl.a library in the compilation
process, the library stops being loaded by rundll32.
After having a look with a debugger, I realized that the DLL its
unloaded after tried to be loaded. Last DLL which tries to load is
ws2_32.dll but at this point I am not really sure if it just something
problematic with it in my compilation process or it is just the last
dependency libcurl is trying to load.
This is the error I receive.
---------------------------
RunDLL
---------------------------
There was a problem starting libtest.dll
The specified module could not be found.
---------------------------
OK
---------------------------
Which makes sense since it's been unloaded from memory. But why?
I tried tons of different configurations but for the sake of
simplicity I configured a separately project and used the following:
./configure \
--prefix=`pwd`/build \
--host=x86_64-w64-mingw32 \
--disable-shared \
--disable-ldap \
--disable-ldaps
make -j`nproc`
make install
------------------- CMakeLists.txt -------------------
cmake_minimum_required(VERSION 3.16)
project(test C)
set(CMAKE_C_STANDARD 99)
set(CMAKE_VERBOSE_MAKEFILE on)
include_directories(extra/curl/include)
link_directories(extra/curl/lib)
add_definitions(-DCURL_STATICLIB -DWINDOWS)
add_library(
test SHARED
library.c library.h
)
target_compile_options(test PRIVATE -Wall)
target_link_libraries(test curl pthread ws2_32)
--------------- mingw-w64-x86_64.cmake ---------------
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" ".dll.a" ".lib" ".a")
------------------------------------------------------
The source code is just a DLLMain entry point + DLLExport function
which call MessageBox an curl_easy_init() to verify everything worked
and that I can build above it. I don't think it would be necessary but
I could include those source files too.
My IDE is CLion and I am compiling the project by specifying in the
cmake section of the project settings
-DCMAKE_TOOLCHAIN_FILE=./mingw-w64-x86_64.cmake.
Since the CMakeLists.txt is set to verbose I can see a lot of output
staying that everything is correct. I guess the most valuable string
is the following mingw32 compilation command.
/usr/bin/x86_64-w64-mingw32-gcc -DCURL_STATICLIB -DWINDOWS
-Dtest_EXPORTS @CMakeFiles/test.dir/includes_C.rsp -g -Wall
-std=gnu99 -o CMakeFiles/test.dir/library.c.obj -c
/home/diego/CLionProjects/test/library.c
I also checked the options used by the compilation process via
curl-config and they seem fine to me.
$ ./curl-config --built-shared --cc --cflags --features --static-libs
no
x86_64-w64-mingw32-gcc
-DCURL_STATICLIB -I/[snipped]/curl/build/include
IPv6
AsynchDNS
/[snipped]/curl/build/lib/libcurl.a -lws2_32
------------------------------------------------------
Could you please point me what I am doing wrong here? Probably is
something I messed up since I am not used to cross compilations
processes.
Many thanks for your help,
Cheers
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-05-06