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了。

相关推荐
lkasi17 分钟前
python文字转wav音频
开发语言·python
白茶等风1213827 分钟前
C#_封装详解
开发语言·c#
程序员阿鹏37 分钟前
ArrayList 与 LinkedList 的区别?
java·开发语言·后端·eclipse·intellij-idea
技术不支持1 小时前
WSL2+Ubuntu 22.04搭建Qt开发环境+中文输入法
linux·运维·服务器·qt·ubuntu
繁依Fanyi1 小时前
使用 Spring Boot + Redis + Vue 实现动态路由加载页面
开发语言·vue.js·pytorch·spring boot·redis·python·算法
星尘安全1 小时前
一种新的电子邮件攻击方式:AiTM
开发语言·网络安全·php·网络钓鱼·aitm
尘浮生1 小时前
Java项目实战II基于Java+Spring Boot+MySQL的洗衣店订单管理系统(开发文档+源码+数据库)
java·开发语言·数据库·spring boot·mysql·maven·intellij-idea
鸽芷咕1 小时前
【Python报错已解决】xlrd.biffh.XLRDError: Excel xlsx file; not supported
开发语言·python·机器学习·bug·excel
铁匠匠匠2 小时前
【C总集篇】第八章 数组和指针
c语言·开发语言·数据结构·经验分享·笔记·学习·算法
编程小白煎堆2 小时前
C语言:枚举类型
java·开发语言