Author Topic: Link Snap7 to Codeblocks  (Read 3041 times)

Offline petrklacek

  • Single posting newcomer
  • *
  • Posts: 1
Link Snap7 to Codeblocks
« on: August 17, 2023, 09:46:33 am »
Hi , i cant import snap7 to codeblocks. I know , on the forum sourceforge of snap7 is a lot of discussion about that , but it seems a bit confusing and unhelpful.
From what subdirectory ,from downloaded file of Snap7 library , to import where and what?
I made that like this =
Search directories -> Compiler = ...\snap7-full-1.4.2\examples\cpp
Search directories -> Linker = ...\snap7-full-1.4.2\release\Windows\Win64
Linker settings -> snap7 ( just written snap7 )
to the file project ..\bin\Debug i added snap7.dll from \snap7-full-1.4.2\release\Windows\Win64

Is it alright? Because if yes , it must be something with compiler . I use MinGW which was installed with codeblocks 64bit. I want c++ project
When i try to compile that , it returning me error of Undefined reference..
Please help , i am exhausted ...
Snap7 is library for communication between computer and S7-xxx PLC of siemens

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1634
Re: Link Snap7 to Codeblocks
« Reply #1 on: August 17, 2023, 12:23:45 pm »
Using Snap implies two steps: compile the library and use the compiled library in your code.

For the first you must create a new library project and add the core, lib and sys folders to the compiler search directories. Add their files to the project and compile. This will create a .a file

For the second you must create a project (console, wxwidgets or whatever), copy there snap7.cpp and snap7.h, add them to the project and link with the .a from the previous step.

You can integrate the two steps as targets of the same project, but this is complex for a beginner.