安装第三方依赖库

$sudo yum -y install zlib-devel
$sudo yum -y install libpng-devel
$sudo yum -y install libcurl-devel
$sudo yum -y install freetype-devel
$sudo yum -y install libjpeg-devel 
$sudo yum -y install libtiff-devel
# 没有依赖库的也直接yum install安装就好了
编译 geos-3.5.0 proj-6.2.0 gdal-3.0.1(当然如果源有得话直接yum都能安装了,那样就是最省事得)
首先,下载:

gdal:http://trac.osgeo.org/gdal/wiki/DownloadSource
geos:http://trac.osgeo.org/geos
proj:http://download.osgeo.org/proj/

接下来检查是否安装了开发环境和编译环境,在终端输入gcc,g++,make,如果提示命令不存在,就说明需要安装编译环境。(例如:g++不存在,终端执行yum install gcc-c++)
接下来安装cmake(可以不装)
cmake -version  #查看是否有旧版本
yum install gcc gcc-c++ #安装基本工具
yum install cmake-gui #安装基本工具
接下来安装sqlite
sudo yum install sqlite-devel
在终端使用cd命令进入proj的目录,依次执行以下3个命令(注意编译顺序先sqlite安装->然后proj->geos->gdal):
proj
./configure --prefix=usr/local/proj
make
make install
geos

我使用的cmake-gui 配置好路径以后点击configure,没有错误后generatle生成unixmakefile
在这里插入图片描述
然后命令行前往geos路径
遇到的问题:
https://trac.osgeo.org/geos/ticket/753

sudo make
sudo make install
gdal

cd 到根目录

./configure --prefix=/usr/local/gdal
sudo make
sudo make install

出现 error: PROJ 6 symbols not found,主要是系统没有安装proj 6或者系统存在多个版本的proj,或者安装了但是gdal找不到proj

解决方法:可以在的gdal ./configure 加上–with-proj=(proj6安装路径)我的如:

–with-proj=usr/local/proj
OSG
cmakelist文件开始添加

set(DESIRED_QT_VERSION "5" CACHE STRING "") 
set(CMAKE_PREFIX_PATH "qt的路径" CACHE PATH "")  #目前不管用
cmake搞定以后cd到osg跟目录输入
cmake .
sudo make
sudo make install

添加环境变量

sudo vim /etc/profile #设置环境变量
export OSG_FILE_PATH=你的data路径
export 	LD_LIBRARY_PATH=你的osglib路径
export 	PATH=$PATH:你的osgbin路径
source /etc/profile #使变量更新

我的环境变量

export PATH=$PATH:/run/media/jinchen/fc18509b-a77b-41ed-9352-e97bd7406904/myosg/cmake-3.9.0-Linux-x86_64/bin
export OSG_FILE_PATH=/run/media/jinchen/fc18509b-a77b-41ed-9352-e97bd7406904/myosg/osg-3.4.0/OpenSceneGraph-Data
export LD_LIBRARY_PATH=/run/media/jinchen/fc18509b-a77b-41ed-9352-e97bd7406904/myosg/osg-3.4.0/osgtest/build/lib64
export PATH=$PATH:/run/media/jinchen/fc18509b-a77b-41ed-9352-e97bd7406904/myosg/osg-3.4.0/osgtest/build/bin
export LD_LIBRARY_PATH=/run/media/jinchen/fc18509b-a77b-41ed-9352-e97bd7406904/myosg/osg-3.4.0/osgearth/build/lib64
export PATH=$PATH:/run/media/jinchen/fc18509b-a77b-41ed-9352-e97bd7406904/myosg/osg-3.4.0/osgearth/build/bin
export LD_LIBRARY_PATH=/run/media/jinchen/fc18509b-a77b-41ed-9352-e97bd7406904/opencv-3.3.1/sdk/lib
export PKG_CONFIG_PATH=/run/media/jinchen/fc18509b-a77b-41ed-9352-e97bd7406904/opencv-3.3.1/sdk/lib/pkgconfig

遇到问题:
1.
我这里在/etc/profile下配置好环境变量后,每次关闭shell窗口后都需要再执行一次source /etc/profile才能生效,这个问题需要在~/.bashrc文件最后添加source /etc/profile,这样问题便得到解决。
测试代码
2.麒麟系统v7.0遇到的问题()fedora内核)
在这里插入图片描述
这个问题是没有安装opengl环境导致的
3.没有yum到libtiff
这个去osgeo下载编译即可
4.编译过程遇到错误:linux must hace c++11 or newer
这个是该Linux操作系统未使用c++11编译代码,查看gcc版本4.8以上即可,不够的需要升级,我的是4.9尝试了在cmake文件中添加:

add_definitions(-std=c++11)

如下安装

sudo yum install -y mesa*
sudo yum install -y freeglut*
sudo yum install -y *GLEW*
osgviewer cow.osg #有问题就是环境变量了具体还得看是什么问题

在这里插入图片描述
OSGEARTH
1.我这边需要两个免费库triton和Silverlining所以我这边需要编译一下
(1)Silverlining 直接make makeinstall安装
(2)triton 需要提前编译,安装显卡驱动,可以查看readme看具体说明,提前编译fftss(https://www.ssisc.org/fftss/index.html.en)包
2.编译好了就可以继续了,编译方法同win可参照之前博客
earth文件
在这里插入图片描述
osgearth_viewer mytest.earth
在这里插入图片描述

opencv编译
所需安装环境
1、安装编译环境

sudo dnf install gcc gcc-c++ ncurses-devel cmake

2、安装gtk+2.x

sudo dnf install gtk2 gtk2-devel gtk2-devel-docs
sudo dnf install libgnome-devel gnome-devel-docs
sudo dnf install zlib glib atk pango gdk-pixbuf2 gdk-pixbuf2-devel

3、安装依赖的包

sudo dnf install gtk+ gtk2-devel pkgconfig python-devel python-numpydoc
sudo dnf install libavc1394 libavc1394-devel libdc1394 libdc1394-devel jasper-devel
sudo dnf install ffmpeg ffmpeg-devel openjpeg-devel libjpeg-devel libpng-devel libtiff-devel

4、最后,就是OpenCV的安装包了,去官网下载即可,传送门:http://opencv.org/

使用cmake生成用于编译安装的makefile文件v会默认安装在/usr/local/目录文件下,若要改变安装位置有选项“-D CMAKE_INSTALL_PREFIX=/usr/local",修改后面的参数即可。
其中命令"cmake -DINSTALL_CREATE_DISTRIB=ON"是必须要加上的,否则编译以后目标文件链接库的时候会出现以下错误

/usr/bin/ld: cannot find -lippicv
collect2: error: ld returned 1 exit status
具体请走传送门:https://github.com/Itseez/opencv/issues/5852

环境配置
1、添加环境变量profile

sudo vim /etc/profile

在最后添加如下内容

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:安装路径/lib/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:安装路径/lib

保存并退出,并执行以下命令使修改生效


sudo source /etc/profile
source /etc/bashrc

2、最后执行

sudo ldconfig

测试
1、首先检查测试是否安装成功

pkg-config --cflags opencv

pkg-config --libs opencv

pkg-config --modversion gtk+-2.0

在这里插入图片描述

2、写一个程序测试test.cpp,源代码如下

#include "opencv/cv.h"
#include "opencv/highgui.h"
int main(int argc, char **argv)
{
        IplImage* pImage;
        if(argc==2 && (pImage=cvLoadImage(argv[1],1))!=0)
        {
                cvNamedWindow("Image",1);
                cvShowImage("Image",pImage);
                cvWaitKey(0);
                cvDestroyWindow("Image");
                cvReleaseImage(&pImage);
                return 0;
        }
        return -1;
}

直接编译

g++ `pkg-config --cflags opencv` -o test test.cpp `pkg-config --libs opencv`

或者编译链接分两部完成

g++ `pkg-config --cflags opencv` -c test.cpp
g++ `pkg-config --libs     opencv` -o test test.o

最后运行

$ ./test test.jpg

qtcreator pro 文件
关于pro文件库添加,右键项目-》添加库-》选择外部库添加对应得lib即可,注意区分debug release

#-------------------------------------------------
#
# Project created by QtCreator 2020-02-18T15:06:31
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = testosgearth
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += main.cpp
QT       += opengl
HEADERS  +=

FORMS    += mainwindow.ui


LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -lOpenThreadsd
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgd
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgDBd
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgGAd
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgUtild
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgViewerd
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgTextd
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgManipulatord
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgQt
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgShadow
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgTerrain
LIBS += -L$$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/lib64/ -losgSim

INCLUDEPATH += $$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/include
DEPENDPATH += $$PWD/../myosg/osg-3.4.0/OSG-3.4.0-SDK/include


LIBS += -L$$PWD/../OSGALL-SDK/osgearth-sdk/lib64/ -losgEarthd
LIBS += -L$$PWD/../OSGALL-SDK/osgearth-sdk/lib64/ -losgEarthUtild
LIBS += -L$$PWD/../OSGALL-SDK/osgearth-sdk/lib64/ -losgEarthQtd
LIBS += -L$$PWD/../OSGALL-SDK/osgearth-sdk/lib64/ -losgEarthAnnotationd
LIBS += -L$$PWD/../OSGALL-SDK/osgearth-sdk/lib64/ -losgEarthFeaturesd
LIBS += -L$$PWD/../OSGALL-SDK/osgearth-sdk/lib64/ -losgEarthSplatd
LIBS += -L$$PWD/../OSGALL-SDK/osgearth-sdk/lib64/ -losgEarthSymbologyd

INCLUDEPATH += $$PWD/../OSGALL-SDK/osgearth-sdk/include
DEPENDPATH += $$PWD/../OSGALL-SDK/osgearth-sdk/include

LIBS += -L$$PWD/../OSGALL-SDK/gdal/lib/ -lgdal

INCLUDEPATH += $$PWD/../OSGALL-SDK/gdal/include
DEPENDPATH += $$PWD/../OSGALL-SDK/gdal/include


LIBS += -L$$PWD/../OSGALL-SDK/geos/lib/ -lgeos

INCLUDEPATH += $$PWD/../OSGALL-SDK/geos/include
DEPENDPATH += $$PWD/../OSGALL-SDK/geos/include


LIBS += -L$$PWD/../OSGALL-SDK/PROJ/lib/ -lproj

INCLUDEPATH += $$PWD/../OSGALL-SDK/PROJ/include
DEPENDPATH += $$PWD/../OSGALL-SDK/PROJ/include

Logo

更多推荐