做網(wǎng)站前需要準(zhǔn)備什么條件深圳網(wǎng)
文章目錄
- 1.背景介紹
- 2.修改makefile
- 2.1.將編譯器由c改成c++
- 2.2.使能opencv庫(kù)
- 2.3.使能Qt庫(kù)
- 3.在代碼中使用Qt庫(kù)函數(shù)
1.背景介紹
建議先查看之前的文章【CodeSys中調(diào)用C語(yǔ)言寫的動(dòng)態(tài)庫(kù)】,了解如何創(chuàng)建一個(gè)能夠被codesys調(diào)用的動(dòng)態(tài)庫(kù)。
假如想要在函數(shù)中使用Qt或者第三方庫(kù)(比如opencv等),可以在其自動(dòng)生成的makefile文件中設(shè)置好相應(yīng)的參數(shù)。
2.修改makefile
修改后的makefile:
##############################################################################
# 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 #添加庫(kù)# 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而做的一些設(shè)置
INCLUDES += -I/usr/include/opencv4\-I/usr/include/opencv4/opencv2
LDLIBS += /usr/lib/x86_64-linux-gnu/libopencv_*.so# #為了能夠使用Qt而做的一些參數(shù)設(shè)置
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++\-I/opt/Qt/5.15.2/gcc_64/include/QtRemoteObjects
LDLIBS += /opt/Qt/5.15.2/gcc_64/lib/*.so
LDFLAGS += -Wl,-rpath,/opt/Qt/5.15.2/gcc_64/lib# include of the SDK makefiles
SDKDIR=/home/yong/Desktop/PLC/ExtensionSDK
include ${SDKDIR}/makefile
主要是做了三個(gè)修改:
2.1.將編譯器由c改成c++
2.2.使能opencv庫(kù)
2.3.使能Qt庫(kù)
這里特別注意一下這個(gè):-Wl,-rpath,/opt/Qt/5.15.2/gcc_64/lib,這條語(yǔ)句是指定了運(yùn)行時(shí)搜索庫(kù)的路徑,沒(méi)有這句的話,雖然可以編譯通過(guò),但是運(yùn)行時(shí)codesys就直接報(bào)錯(cuò),無(wú)法下載了??梢钥纯催@個(gè)資料的介紹【GCC/G++選項(xiàng) -Wl,-rpath=】
我是如何知道需要寫這個(gè)的?我是從QtCreator的編譯輸出看到的:
3.在代碼中使用Qt庫(kù)函數(shù)
這樣操作之后,在include對(duì)應(yīng)的頭文件后,就可以在函數(shù)中使用opencv、Qt了。