CodeSys通过C函数接口调用Qt

建议先查看之前的文章【CodeSys中调用C语言写的动态库】,了解如何创建一个能够被codesys调用的动态库。

假如想要在函数中使用Qt或者第三方库(比如opencv等),可以在其自动生成的makefile文件中设置好相应的参数。

比如我这里就是这样:

bash 复制代码
##############################################################################
#	Copyright:		Copyright CODESYS Development GmbH
#	Program:		Extension API for the Linux SL products
##############################################################################

#
# with this makefile you can influence the build of your component 
#
#
# Hints:
#  - the name of the *Itf.m4 file in this folder will be used as name of the shared object (and component name)
#  - all C files in this folder will be compiled by default
# 

# set versions of your shared object
# must be single digit, decimal
MAJORVER=0
MINORVER=1

# set a component version (must match your IEC library version)
# must be 4 bytes, hexadecimal
CMPVERSION=0x01000000

# set a component ID 
# must be 2 bytes >= 0x2000 and hexadecimal and can be used to differentiate different components
CMPID=0x2000

# set your tools
DOS2UNIX = dos2unix
M4 = m4

# set a compiler
#CC = gcc
CC = g++


#INCLUDEPATH += /usr/include/opencv4
#LIBS += /usr/lib/x86_64-linux-gnu/libopencv_*.so          #添加库

# add some compiler flags (with += )
#CFLAGS += -g

# add some include paths (with +=)
#INCLUDES += -I.

# add some linker flags (with += )
#LDFLAGS += 

# add some libraries that you might need (with += )
#LDLIBS += -lc

# 为了能够使用opencv而做的一些设置
INCLUDES += -I/usr/include/opencv4\
			-I/usr/include/opencv4/opencv2
LDLIBS += /usr/lib/x86_64-linux-gnu/libopencv_*.so

# 为了能够使用Qt而做的一些参数设置
INCLUDES += -I/opt/Qt/5.15.2/gcc_64/include\
		    -I/opt/Qt/5.15.2/gcc_64/include/QtCore\
		    -I/opt/Qt/5.15.2/gcc_64/mkspecs/linux-g++
LDLIBS += /opt/Qt/5.15.2/gcc_64/lib/*.so

# include of the SDK makefiles
SDKDIR=/home/yong/Desktop/PLC/ExtensionSDK
include ${SDKDIR}/makefile

主要是做了三个修改:

1.将编译器由c改成c++

2.使能opencv库

3.使能Qt库

这样操作之后,在include对应的头文件后,就可以在函数中使用opencv、Qt了。

相关推荐
CHTXRT1 分钟前
2025第十六届蓝桥杯大赛(软件赛)网络安全赛 Writeup
c语言·网络·web安全·网络安全·蓝桥杯·wireshark
钢铁男儿5 分钟前
C# 深入理解类:面向对象编程的核心数据结构
开发语言·数据结构·c#
karatttt11 分钟前
用go从零构建写一个RPC(仿gRPC,tRPC)--- 版本1
后端·qt·rpc·架构·golang
Doker 多克30 分钟前
Python-Django系列—部件
开发语言·python
江沉晚呤时1 小时前
深入解析 ASP.NET Core 中的 ResourceFilter
开发语言·c#·.net·lucene
huangyuchi.1 小时前
【C++11】Lambda表达式
开发语言·c++·笔记·c++11·lambda·lambda表达式·捕捉列表
XiaoyuEr_66881 小时前
如何创建一个C#项目(基于VS2022版)
开发语言·c#
小智学长 | 嵌入式1 小时前
单片机-89C51部分:4、固件烧录
c语言·单片机·嵌入式硬件
Mercury-circle2 小时前
JavaScript基础知识合集笔记1——数据类型
开发语言·javascript·笔记
Chase_______2 小时前
Java后端开发——分层解耦详解
java·开发语言·spring·web