# CMakeList.txt: файл проекта CMake верхнего уровня; проведите глобальную конфигурацию
# и включите сюда подпроекты.
#
cmake_minimum_required (VERSION 3.8)

# Включение горячей перезагрузки для компиляторов MSVC, если поддерживается.
if (POLICY CMP0141)
  cmake_policy(SET CMP0141 NEW)
  set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

if(WIN32)
	set(CMAKE_TOOLCHAIN_FILE "d:/vcpkg/scripts/buildsystems/vcpkg.cmake")
endif()

project ("s72kafka")

# Добавьте источник в исполняемый файл этого проекта.
add_executable (s72kafka "s72kafka.cpp" "s72kafka.h" "json.hpp" "snap7_client.h" "snap7_client.cpp" "safe_queue.h" "safe_queue.cpp" "ip.hpp")

if (CMAKE_VERSION VERSION_GREATER 3.12)
  set_property(TARGET s72kafka PROPERTY CXX_STANDARD 20)
endif()

# TODO: Добавьте тесты и целевые объекты, если это необходимо.

if(WIN32)
	find_package(RdKafka CONFIG REQUIRED)
	find_package(hiredis CONFIG REQUIRED)
	find_package(redis++ CONFIG REQUIRED)
	find_package(snap7 CONFIG REQUIRED)
	target_link_libraries(s72kafka PRIVATE RdKafka::rdkafka RdKafka::rdkafka++ hiredis::hiredis redis++::redis++ snap7::snap7)
endif()

if(UNIX)
	include_directories(/opt/open62541/include)
	link_directories(/opt/open62541/lib)
	#find_package(open62541 REQUIRED)
	target_link_libraries(s72kafka PRIVATE rdkafka rdkafka++ hiredis redis++)
endif()




>------ Сборка запущено: проект: CMakeLists, конфигурация: Debug ------
  [1/4] Building CXX object CMakeFiles\s72kafka.dir\safe_queue.cpp.obj
  [2/4] Building CXX object CMakeFiles\s72kafka.dir\s72kafka.cpp.obj
  [3/4] Building CXX object CMakeFiles\s72kafka.dir\snap7_client.cpp.obj
  [4/4] Linking CXX executable s72kafka.exe
  FAILED: s72kafka.exe 
  C:\Windows\system32\cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --msvc-ver=1944 --intdir=CMakeFiles\s72kafka.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo CMakeFiles\s72kafka.dir\s72kafka.cpp.obj CMakeFiles\s72kafka.dir\snap7_client.cpp.obj CMakeFiles\s72kafka.dir\safe_queue.cpp.obj  /out:s72kafka.exe /implib:s72kafka.lib /pdb:s72kafka.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console  D:\vcpkg\installed\x64-windows\debug\lib\rdkafka++.lib  D:\vcpkg\installed\x64-windows\debug\lib\redis++.lib  D:\vcpkg\installed\x64-windows\lib\snap7.lib  D:\vcpkg\installed\x64-windows\debug\lib\rdkafka.lib  D:\vcpkg\installed\x64-windows\debug\lib\lz4d.lib  secur32.lib  D:\vcpkg\installed\x64-windows\debug\lib\hiredisd.lib  crypt32.lib  wsock32.lib  ws2_32.lib  winmm.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && C:\Windows\system32\cmd.exe /C "cd /D C:\Users\a_zagidulin\source\repos\opc2kafka\s72kafka\out\build\x64-debug && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file D:/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary C:/Users/a_zagidulin/source/repos/opc2kafka/s72kafka/out/build/x64-debug/s72kafka.exe -installedDir D:/vcpkg/installed/x64-windows/debug/bin -OutVariable out""
  LINK Pass 1: command "C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\link.exe /nologo CMakeFiles\s72kafka.dir\s72kafka.cpp.obj CMakeFiles\s72kafka.dir\snap7_client.cpp.obj CMakeFiles\s72kafka.dir\safe_queue.cpp.obj /out:s72kafka.exe /implib:s72kafka.lib /pdb:s72kafka.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console D:\vcpkg\installed\x64-windows\debug\lib\rdkafka++.lib D:\vcpkg\installed\x64-windows\debug\lib\redis++.lib D:\vcpkg\installed\x64-windows\lib\snap7.lib D:\vcpkg\installed\x64-windows\debug\lib\rdkafka.lib D:\vcpkg\installed\x64-windows\debug\lib\lz4d.lib secur32.lib D:\vcpkg\installed\x64-windows\debug\lib\hiredisd.lib crypt32.lib wsock32.lib ws2_32.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\s72kafka.dir/intermediate.manifest CMakeFiles\s72kafka.dir/manifest.res" failed (exit code 1120) with the following output:
C:\Users\a_zagidulin\source\repos\opc2kafka\s72kafka\out\build\x64-debug\snap7_client.cpp.obj : error LNK2019: ссылка на неразрешенный внешний символ "public: int __cdecl TSnap7MicroClient::ConnectTo(char const *,int,int)" (?ConnectTo@TSnap7MicroClient@@QEAAHPEBDHH@Z) в функции "private: void __cdecl Snap7Client::run(void)" (?run@Snap7Client@@AEAAXXZ).
C:\Users\a_zagidulin\source\repos\opc2kafka\s72kafka\out\build\x64-debug\snap7_client.cpp.obj : error LNK2019: ссылка на неразрешенный внешний символ "public: int __cdecl TSnap7MicroClient::Disconnect(void)" (?Disconnect@TSnap7MicroClient@@QEAAHXZ) в функции "private: void __cdecl Snap7Client::run(void)" (?run@Snap7Client@@AEAAXXZ).
C:\Users\a_zagidulin\source\repos\opc2kafka\s72kafka\out\build\x64-debug\snap7_client.cpp.obj : error LNK2019: ссылка на неразрешенный внешний символ "public: int __cdecl TSnap7MicroClient::DBRead(int,int,int,void *)" (?DBRead@TSnap7MicroClient@@QEAAHHHHPEAX@Z) в функции "private: bool __cdecl Snap7Client::readArea(int,int,int,int,void *)" (?readArea@Snap7Client@@AEAA_NHHHHPEAX@Z).
C:\Users\a_zagidulin\source\repos\opc2kafka\s72kafka\out\build\x64-debug\snap7_client.cpp.obj : error LNK2019: ссылка на неразрешенный внешний символ "public: int __cdecl TSnap7MicroClient::MBRead(int,int,void *)" (?MBRead@TSnap7MicroClient@@QEAAHHHPEAX@Z) в функции "private: bool __cdecl Snap7Client::readArea(int,int,int,int,void *)" (?readArea@Snap7Client@@AEAA_NHHHHPEAX@Z).
C:\Users\a_zagidulin\source\repos\opc2kafka\s72kafka\out\build\x64-debug\snap7_client.cpp.obj : error LNK2019: ссылка на неразрешенный внешний символ "public: int __cdecl TSnap7MicroClient::EBRead(int,int,void *)" (?EBRead@TSnap7MicroClient@@QEAAHHHPEAX@Z) в функции "private: bool __cdecl Snap7Client::readArea(int,int,int,int,void *)" (?readArea@Snap7Client@@AEAA_NHHHHPEAX@Z).
C:\Users\a_zagidulin\source\repos\opc2kafka\s72kafka\out\build\x64-debug\snap7_client.cpp.obj : error LNK2019: ссылка на неразрешенный внешний символ "public: int __cdecl TSnap7MicroClient::ABRead(int,int,void *)" (?ABRead@TSnap7MicroClient@@QEAAHHHPEAX@Z) в функции "private: bool __cdecl Snap7Client::readArea(int,int,int,int,void *)" (?readArea@Snap7Client@@AEAA_NHHHHPEAX@Z).
C:\Users\a_zagidulin\source\repos\opc2kafka\s72kafka\out\build\x64-debug\snap7_client.cpp.obj : error LNK2019: ссылка на неразрешенный внешний символ "public: __cdecl TSnap7Client::TSnap7Client(void)" (??0TSnap7Client@@QEAA@XZ) в функции "public: __cdecl Snap7Client::Snap7Client(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,int,class std::vector<struct Tag,class std::allocator<struct Tag> > *,class SafeQueue *)" (??0Snap7Client@@QEAA@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHPEAV?$vector@UTag@@V?$allocator@UTag@@@std@@@2@PEAVSafeQueue@@@Z).
  
C:\Users\a_zagidulin\source\repos\opc2kafka\s72kafka\out\build\x64-debug\s72kafka.exe : fatal error LNK1120: неразрешенных внешних элементов: 7
  
  ninja: build stopped: subcommand failed.


в документации сказано

Snap7 MicroClient
In the Snap7 project, TSnap7MicroClient is the ancestor of TSnap7Client class.

It’s not exported, i.e. you cannot reference it from outside the library, and the only way to use it is to embed it in your C++ source code.

TSnap7MicroClient implements the body of all S7 Client jobs and the synchronous interface functions.

The exported TSnap7Client, only adds the remaining asynchronous functions but does not introduce any new S7 behavior.

Why we are speaking about an internal object ?

The micro client is thread independent and only relies on the sockets layer, i.e. you would embed it in your source code if:

·         Your application will run in a micro-OS that has no threads layer.

·         Your application will run in a realtime-OS (such as QNX) or in an OS that has not a standard threads layer (neither Windows nor posix). In this case you may create a native thread and use the micro client inside of it.

 

Micro client “extrapolation” is provided by design, there is a well-defined group of independent files to use.

See the chapter Embedding Snap7 Microclient for further information.