hasherezade / libpeconv

A library to load, manipulate, dump PE files. See also: https://github.com/hasherezade/libpeconv_tpl
https://hasherezade.github.io/libpeconv
BSD 2-Clause "Simplified" License
1.07k stars 176 forks source link

error LNK2001 #8

Closed MVoz closed 5 years ago

MVoz commented 5 years ago

msvc ver 2017 x64 dynamic \\ DEBUG

user32.lib(USER32.dll) : error LNK2001: unresolved external symbol __delayLoadHelper2

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") set(DELAYLOAD_FLAG "/DELAYLOAD:\"user32.dll\"" )

set (srcs main.cpp )

set (hdrs )

add_executable ( ${PROJECT_NAME} ${hdrs} ${srcs}) set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${DELAYLOAD_FLAG}")

https://docs.microsoft.com/ru-ru/cpp/build/reference/specifying-dlls-to-delay-load?view=vs-2019

cl t.cpp user32.lib delayimp.lib /link /DELAYLOAD:user32.dll

addstd lib delayimp.lib ?


add_executable ( ${PROJECT_NAME} ${hdrs} ${srcs})
target_link_libraries(${PROJECT_NAME} delayimp.lib)
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " ${DELAYLOAD_FLAG}")
hasherezade commented 5 years ago

It is weird, I cannot reproduce your problem. I also use Visual Studio 2017 x64. I tried to compile it in a Debug configuration and had no issues.

compile_success

Also on AppVeyor it compiles cleanly and passes all the tests, so I don't think my CMake file is wrong.

Please make sure that this problem is not caused by some misconfiguration on your side.

And as a temporary workaround, to make the library work, you can just disable building tests (this exe with delayload imports is just a part of the test cases, not of the libpeconv itself). Tests can be disabled just by unmarking the option PECONV_BUILD_TESTING:

disable_tests

MVoz commented 5 years ago

CMAKE_GENERATOR Ninja

I wanted to make a port of this library https://github.com/microsoft/vcpkg

libpeconv.zip

MVoz commented 5 years ago

Oops ... accidentally closed))

hasherezade commented 5 years ago

Please check if this update helped you. I cannot really check because for me it worked before too.

MVoz commented 5 years ago

Apparently you need to add to each test and maybe I'm mistaken with the parameters of cmake

hasherezade commented 5 years ago

But this is the only exe in the project that uses delayload imports...

MVoz commented 5 years ago

ok, I'll get to the working machine, check

\google translate ))

hasherezade commented 5 years ago

ok, let me know...

MVoz commented 5 years ago

ok

tests\tests.exe

TESTS DEPLOYED!

Supply the test id!

install block in CMakeLists.txt?

install(TARGETS ${targets}
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
)

Ok, this is little things

hasherezade commented 5 years ago

@Voskrese - I am glad that it worked now. I can add those install blocks too, it is not a problem. But please make a separate issue for this, because it is a different topic than those linking problems.