chronoxor / CppServer

Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution
MIT License
1.42k stars 285 forks source link

Static library linking example (Windows) #68

Open dmitrystvorkin opened 2 years ago

dmitrystvorkin commented 2 years ago

Hello, could you help please with an example/advice?

I have builded a project with VS2022 and get cppserver.lib file, but withour a header file, I can't use it in my own code. For example I want to connect this TCP server for MT5 dll plugin and use the cppserver.lib as static library.

Could you advice please, how to do it in better way?

chronoxor commented 2 years ago

You cannot use static cppserver.lib without headers. After you compile CppServer you need to add cppserver.lib to your project, and also add ..\CppServer\include path to Include Directories.

It is very easy to do if you have your own CMakeLists.txt. Just create CppServer.cmake:

if(NOT TARGET cppserver)

  # Module flag
  set(CPPSERVER_MODULE Y)

  # Module subdirectory
  add_subdirectory("CppServer")

  # Module folder
  set_target_properties(cppserver PROPERTIES FOLDER "modules/CppServer")

endif()

Include it into your CMakeLists.txt and link your target over cppserver:

include("..\your_path\CppServer.cmake")

target_link_libraries(myMT5plugin cppserver)