Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Build dynamic library failed on Windows #34

Closed
theidexisted opened this issue Nov 7, 2017 · 10 comments
Closed

Build dynamic library failed on Windows #34

theidexisted opened this issue Nov 7, 2017 · 10 comments

Comments

@theidexisted
Copy link

Hi, I'am trying to build a dll library on Windows, but got linking error:

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2001	unresolved external symbol __imp_listen	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\tcp_socket.obj	1	
Error	LNK1120	20 unresolved externals	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\msvc15\x64\Release\tacopie.dll	1	
Error	LNK2001	unresolved external symbol __imp_accept	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\tcp_socket.obj	1	
Error	LNK2001	unresolved external symbol __imp_bind	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_self_pipe.obj	1	
Error	LNK2001	unresolved external symbol __imp_closesocket	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_self_pipe.obj	1	
Error	LNK2001	unresolved external symbol __imp_connect	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_self_pipe.obj	1	
Error	LNK2001	unresolved external symbol __imp_freeaddrinfo	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_tcp_socket.obj	1	
Error	LNK2001	unresolved external symbol __imp_getaddrinfo	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_tcp_socket.obj	1	
Error	LNK2001	unresolved external symbol __imp_getsockname	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_self_pipe.obj	1	
Error	LNK2001	unresolved external symbol __imp_htonl	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_self_pipe.obj	1	
Error	LNK2001	unresolved external symbol __imp_htons	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_tcp_socket.obj	1	
Error	LNK2001	unresolved external symbol __imp_inet_ntoa	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\tcp_socket.obj	1	
Error	LNK2001	unresolved external symbol __imp_ioctlsocket	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_self_pipe.obj	1	
Error	LNK2001	unresolved external symbol __imp_recv	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\tcp_socket.obj	1	
Error	LNK2001	unresolved external symbol __imp_recvfrom	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_self_pipe.obj	1	
Error	LNK2001	unresolved external symbol __imp_select	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\io_service.obj	1	
Error	LNK2001	unresolved external symbol __imp_send	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\tcp_socket.obj	1	
Error	LNK2001	unresolved external symbol __imp_sendto	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_self_pipe.obj	1	
Error	LNK2001	unresolved external symbol __imp_socket	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_self_pipe.obj	1	
Error	LNK2001	unresolved external symbol __imp_WSAGetLastError	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\windows_tcp_socket.obj	1	
Error	LNK2001	unresolved external symbol __WSAFDIsSet	tacopie	Z:\cpp_redis4.2.0\cpp_redis-4.2.0\tacopie\msvc15\io_service.obj	1	

How to reproduce:

  • Use latest tacopie tag(3.1.0)
  • Change visual studio solution configure: Configuration Type: static to dynamic
@Cylix
Copy link
Owner

Cylix commented Nov 13, 2017

Hi,

Sorry for the late reply.

The output looks similar to the one reported on cpp_redis#46. At the time, the error was due to the fact the author was not linking with Ws2_32.lib.
If you are still having this issue, can you let me know if you are compiling with this system library? If not, can you try to link with it?

Best

@yuangu
Copy link
Contributor

yuangu commented Nov 14, 2017

add this code in you project:
#pragma comment( lib, "ws2_32.lib")

@Cylix
Copy link
Owner

Cylix commented Nov 15, 2017

interested, I didn't know about that #pragma comment feature, will add

@theidexisted
Copy link
Author

Add linkage of ws2_32.lib does not work, I get linking error still.

@yuangu
Copy link
Contributor

yuangu commented Nov 15, 2017

what your compiler?

@theidexisted
Copy link
Author

I'm using vs2015 with win server 2008

@yuangu
Copy link
Contributor

yuangu commented Nov 16, 2017

@Cylix
I know what the reason。this code add to tacopie file。so not't compile into the dll (in other words, this code not wrok).

#ifdef _WIN32 #pragma comment( lib, "ws2_32.lib") #endif /* _WIN32 */

your try to add
#pragma comment( lib, "ws2_32.lib") into windows_tcp_socket.cpp files.

sorry for my english.

@yuangu
Copy link
Contributor

yuangu commented Nov 16, 2017

image

@theidexisted
Copy link
Author

@yuangu @Cylix
Many thanks, but it's bad to add library dependency in source code. I prefer to add ws2_32.lib in the project configuration. The configure path:
Configuration Property -> Linker -> Input -> Additional dependency.

What's more, this project lacks the exporting set for making a DLL on windows. We need to change the declaration like this:

- void set_nb_workers(std::size_t nb_threads);
+ __declspec(dllexport) void set_nb_workers(std::size_t nb_threads);

If you agree with me, I will submit a patch latter.

@Cylix
Copy link
Owner

Cylix commented Dec 3, 2017

Hi,

Sorry I missed the updates on this issue.
@yuangu I will make the change, it makes sense.
@Prehistoric-penguin you can definitely make this change, I would be happy to merge it. I would be cautious though: be careful not to break unix build.

I'm closing this issue as the original problem seems resolved.

Best

@Cylix Cylix closed this as completed Dec 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants