-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix link problem on win32 MSVC #1000
Conversation
This feels like a symptom of a larger problem. Whatever the root cause, I suggest to investigate that first. |
First of all, I could reproduce your issue with the following commands: cd /d "%USERPROFILE%"
git clone https://github.com/lz4/lz4.git lz4-issue-1000
cd lz4-issue-1000
cd build\cmake
md msvc-2019
cd msvc-2019
cmake .. -G "Visual Studio 16 2019" -A x64
cmake --build . --config Release But I think the root cause of this issue is current structure of LZ4DIR := ../lib
LIBFILES = $(wildcard $(LZ4DIR)/*.c)
SRCFILES = $(sort $(LIBFILES) $(wildcard *.c))
OBJFILES = $(SRCFILES:.c=.o)
lz4: $(OBJFILES)
$(CC) $(FLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS) It doesn't link any library file. It explicitly compiles and links all library and CLI files from source code directly. On the other hand,
It compiles (static or shared) library first. And it links the library to build lz4 CLI. Since this linking is the root cause of the issue, I think any linkage tweaking doesn't resolve it. I'm not sure about convention of cmake community. But again, I suppose |
I think if it have a static library, link to it first is a good idea because this don't need build same source files again. |
Maybe I can change it to this. If it have a static library, link to it. If not, build library files again. if(WIN32)
if(BUILD_STATIC_LIBS)
set(LZ4_LINK_LIBRARY lz4_static)
else()
list(APPEND LZ4_CLI_SOURCES ${LZ4_SOURCES})
endif()
else()
# link to shared whenever possible, to static otherwise
if(BUILD_SHARED_LIBS)
set(LZ4_LINK_LIBRARY lz4_shared)
else()
set(LZ4_LINK_LIBRARY lz4_static)
endif()
endif()
|
You're right. I also realized #define LZ4_STATIC_LINKING_ONLY
#include "lz4.h"
#define LZ4_HC_STATIC_LINKING_ONLY
#include "lz4hc.h" Therefore, lz4 CLI must be linked with static library. So, I believe this issue is not only for WIN32 + MSVC. Just in case, I checked difference of dependency of # make
cd
git clone https://github.com/lz4/lz4.git lz4-issue-1000
cd lz4-issue-1000
make
ldd ./lz4
# cmake
cd build/cmake
mkdir issue-1000
cd issue-1000
cmake ..
make
ldd ./lz4
It seems 28db4ac (#296) introduced this change. @Cyan4973 do you know any additional context of it? |
I agree. The safest solution would be to remove the recipe which tries to build the |
So just if(BUILD_STATIC_LIBS)
set(LZ4_LINK_LIBRARY lz4_static)
else()
list(APPEND LZ4_CLI_SOURCES ${LZ4_SOURCES})
endif() |
I see, I will add it. |
Looks good to me ! |
On win32, LZ4LIB_STATIC_API will not exported to dll. So in this case, link static library first.