C++ 卡拉Python/C++;扩展-导入错误:未定义符号Ipopt

C++ 卡拉Python/C++;扩展-导入错误:未定义符号Ipopt,c++,setuptools,ipopt,carla,C++,Setuptools,Ipopt,Carla,我在CARLA 0.9.8 trafficmanager中实现了一个MPC控制器。MPC控制器依赖于IPOPT 卡拉使命令(makerebuild;makepythonapi)正常工作 但是,python脚本spawn\u npc.py中的import carla抛出以下错误: ImportError: /home/DNDE.EMEA.DENSO/cha/.cache/Python-Eggs/carla-0.9.8-py2.7-linux-x86_64.egg-tmp/carla/libcarl

我在CARLA 0.9.8 trafficmanager中实现了一个MPC控制器。MPC控制器依赖于IPOPT

卡拉使命令(
makerebuild;makepythonapi
)正常工作

但是,python脚本
spawn\u npc.py
中的
import carla
抛出以下错误:

ImportError: /home/DNDE.EMEA.DENSO/cha/.cache/Python-Eggs/carla-0.9.8-py2.7-linux-x86_64.egg-tmp/carla/libcarla.so: undefined symbol: _ZN5Ipopt16IpoptApplicationC1Ebb
在谷歌搜索了几个小时后,我假设我必须修改文件
setup.py
,以便包含并链接
/usr/local/lib
中的ipopt库

但我的试错程序没有成功

setup.py文件是:

#!/usr/bin/env python

# Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma de
# Barcelona (UAB).
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.

from setuptools import setup, Extension

import fnmatch
import os
import platform
import sys


def get_libcarla_extensions():
    include_dirs = ['dependencies/include']

    library_dirs = ['dependencies/lib']
    libraries = []


    sources = ['source/libcarla/libcarla.cpp']

    def walk(folder, file_filter='*'):
        for root, _, filenames in os.walk(folder):
            for filename in fnmatch.filter(filenames, file_filter):
                yield os.path.join(root, filename)

    if os.name == "posix":
        # @todo Replace deprecated method.
        linux_distro = platform.dist()[0]  # pylint: disable=W1505
        if linux_distro.lower() in ["ubuntu", "debian", "deepin"]:
            pwd = os.path.dirname(os.path.realpath(__file__))
            pylib = "libboost_python%d%d.a" % (sys.version_info.major,
                                               sys.version_info.minor)
            extra_link_args = [
                os.path.join(pwd, 'dependencies/lib/libcarla_client.a'),
                os.path.join(pwd, 'dependencies/lib/librpc.a'),
                os.path.join(pwd, 'dependencies/lib/libboost_filesystem.a'),
                os.path.join(pwd, 'dependencies/lib/libRecast.a'),
                os.path.join(pwd, 'dependencies/lib/libDetour.a'),
                os.path.join(pwd, 'dependencies/lib/libDetourCrowd.a'),
                os.path.join(pwd, 'dependencies/lib', pylib)]
            extra_compile_args = [
                '-isystem', 'dependencies/include/system', '-fPIC', '-std=c++14',
                '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wno-self-assign-overloaded',
                '-Wdeprecated', '-Wno-shadow', '-Wuninitialized', '-Wunreachable-code',
                '-Wpessimizing-move', '-Wold-style-cast', '-Wnull-dereference',
                '-Wduplicate-enum', '-Wnon-virtual-dtor', '-Wheader-hygiene',
                '-Wconversion', '-Wfloat-overflow-conversion',
                '-DBOOST_ERROR_CODE_HEADER_ONLY', '-DLIBCARLA_WITH_PYTHON_SUPPORT'
            ]
            if 'BUILD_RSS_VARIANT' in os.environ and os.environ['BUILD_RSS_VARIANT'] == 'true':
                print('Building AD RSS variant.')
                extra_compile_args += ['-DLIBCARLA_RSS_ENABLED']
                extra_link_args += [os.path.join(pwd, 'dependencies/lib/libad-rss.a')]

            if 'TRAVIS' in os.environ and os.environ['TRAVIS'] == 'true':
                print('Travis CI build detected: disabling PNG support.')
                extra_link_args += ['-ljpeg', '-ltiff']
                extra_compile_args += ['-DLIBCARLA_IMAGE_WITH_PNG_SUPPORT=false']
            else:
                extra_link_args += ['-lpng', '-ljpeg', '-ltiff']
                extra_compile_args += ['-DLIBCARLA_IMAGE_WITH_PNG_SUPPORT=true']
            # @todo Why would we need this?
            include_dirs += ['/usr/lib/gcc/x86_64-linux-gnu/7/include']
            library_dirs += ['/usr/lib/gcc/x86_64-linux-gnu/7']
            extra_link_args += ['/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a']
        else:
            raise NotImplementedError
    elif os.name == "nt":
        sources += [x for x in walk('dependencies/include/carla', '*.cpp')]

        pwd = os.path.dirname(os.path.realpath(__file__))
        pylib = 'libboost_python%d%d' % (
            sys.version_info.major,
            sys.version_info.minor)

        extra_link_args = ['shlwapi.lib' ]

        required_libs = [
            pylib, 'libboost_filesystem',
            'rpc.lib', 'carla_client.lib',
            'libpng.lib', 'zlib.lib',
            'Recast.lib', 'Detour.lib', 'DetourCrowd.lib']

        # Search for files in 'PythonAPI\carla\dependencies\lib' that contains
        # the names listed in required_libs in it's file name
        libs = [x for x in os.listdir('dependencies/lib') if any(d in x for d in required_libs)]

        for lib in libs:
            extra_link_args.append(os.path.join(pwd, 'dependencies/lib', lib))

        # https://docs.microsoft.com/es-es/cpp/porting/modifying-winver-and-win32-winnt
        extra_compile_args = [
            '/experimental:external', '/external:I', 'dependencies/include/system',
            '/DBOOST_ALL_NO_LIB', '/DBOOST_PYTHON_STATIC_LIB',
            '/DBOOST_ERROR_CODE_HEADER_ONLY', '/D_WIN32_WINNT=0x0600', '/DHAVE_SNPRINTF',
            '/DLIBCARLA_WITH_PYTHON_SUPPORT', '-DLIBCARLA_IMAGE_WITH_PNG_SUPPORT=true']
    else:
        raise NotImplementedError

    depends = [x for x in walk('source/libcarla')]
    depends += [x for x in walk('dependencies')]

    def make_extension(name, sources):

        return Extension(
            name,
            sources=sources,
            include_dirs=include_dirs,
            library_dirs=library_dirs,
            libraries=libraries,
            extra_compile_args=extra_compile_args,
            extra_link_args=extra_link_args,
            language='c++14',
            depends=depends)

    print('compiling:\n  - %s' % '\n  - '.join(sources))

    return [make_extension('carla.libcarla', sources)]


setup(
    name='carla',
    version='0.9.8',
    package_dir={'': 'source'},
    packages=['carla'],
    ext_modules=get_libcarla_extensions(),
    license='MIT License',
    description='Python API for communicating with the CARLA server.',
    url='https://github.com/carla-simulator/carla',
    author='The CARLA team',
    author_email='carla.simulator@gmail.com',
    include_package_data=True)
#/usr/bin/env python
#版权所有(c)2019年自治大学计算机视觉中心(CVC)
#巴塞罗那(UAB)。
#
#本作品根据麻省理工学院许可证条款获得许可。
#有关副本,请参阅。
从设置工具导入设置,扩展
导入fnmatch
导入操作系统
导入平台
导入系统
def get_libcarla_extensions():
include_dirs=['dependencies/include']
库_dirs=['dependencies/lib']
库=[]
sources=['source/libcarla/libcarla.cpp']
def walk(文件夹,文件过滤器='*'):
对于os.walk(文件夹)中的根目录文件名:
对于fnmatch.filter中的文件名(文件名、文件\过滤器):
产生os.path.join(根目录,文件名)
如果os.name==“posix”:
#@todo替换已弃用的方法。
linux#u distro=platform.dist()[0]#pylint:disable=W1505
如果linux_distro.lower()位于[“ubuntu”、“debian”、“deepin”]:
pwd=os.path.dirname(os.path.realpath(_文件__))
pylib=“libboost\u python%d%d.a”%(sys.version\u info.major,
系统版本(信息次要)
额外链接参数=[
join(pwd,'dependencies/lib/libcarla_client.a'),
join(pwd'dependencies/lib/librpc.a'),
join(pwd,'dependencies/lib/libboost_filesystem.a'),
join(pwd'dependencies/lib/libRecast.a'),
join(pwd'dependencies/lib/libDetour.a'),
join(pwd'dependencies/lib/libDetourCrowd.a'),
join(pwd,'dependencies/lib',pylib)]
额外编译参数=[
“-isystem”、“dependencies/include/system”、“-fPIC”、“-std=c++14”,
'-Werror'、'-Wall'、'-Wextra'、'-Wpedantic'、'-Wno自分配重载',
'-Wdeprecated'、'-Wno shadow'、'-Wuninitialized'、'-Wunreachable code',
“-wPressizing move”、“-Wold style cast”、“-Wnull dereference”,
“-wdupplicate enum',”-Wnon virtual dtor',“-Wheader hygiene',
'-Wconversion','-Wfloat溢出转换',
“-DBOOST\u ERROR\u CODE\u HEADER\u ONLY”,“-DLIBCARLA\u带有PYTHON\u支持”
]
如果os.environ和os.environ中的“BUILD_RSS_VARIANT”['BUILD_RSS_VARIANT']='true':
打印('构建广告RSS变体')
额外编译参数+=['-DLIBCARLA\u启用RSS']
额外链接参数+=[os.path.join(pwd,'dependencies/lib/libad rss.a')]
如果os.environ和os.environ中的“TRAVIS”['TRAVIS']=='true':
打印('检测到Travis CI生成:禁用PNG支持')
额外链接参数+=['-ljpeg','-ltiff']
额外的编译参数+=['-DLIBCARLA\u图像,带有PNG\u支持=false']
其他:
额外链接参数+=['-lpng','-ljpeg','-ltiff']
额外的编译参数+=['-DLIBCARLA\u图像,支持为true']
#@todo我们为什么需要这个?
include_dirs+=['/usr/lib/gcc/x86_64-linux-gnu/7/include']
库_dirs+=['/usr/lib/gcc/x86_64-linux-gnu/7']
额外链接参数+=['/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a']
其他:
引发未实现的错误
elif os.name==“nt”:
sources+=[x代表行走中的x('dependencies/include/carla','*.cpp')]
pwd=os.path.dirname(os.path.realpath(_文件__))
pylib='libboost_python%d%d'%(
sys.version_info.major,
系统版本(信息次要)
额外链接参数=['shlwapi.lib']
所需的库=[
pylib,‘libboost_文件系统’,
'rpc.lib'、'carla_client.lib',
'libpng.lib'、'zlib.lib',
'Recast.lib'、'Detour.lib'、'DetourCrowd.lib']
#在“PythonAPI\carla\dependencies\lib”中搜索包含
#文件名中必需的库中列出的名称
libs=[x表示os.listdir中的x('dependencies/lib')(如果有的话)(d表示x中的d表示所需的\u libs中的d)]
对于lib中的lib:
额外链接参数附加(os.path.join(pwd,'dependencies/lib',lib))
# https://docs.microsoft.com/es-es/cpp/porting/modifying-winver-and-win32-winnt
额外编译参数=[
“/experimental:external”,“/external:I”,“dependencies/include/system”,
“/DBOOST_ALL_NO_LIB”、“/DBOOST_PYTHON_STATIC_LIB”,
“/DBOOST\u ERROR\u CODE\u HEADER\u ONLY”、“/D\u WIN32\u WINNT=0x0600”、“/DHAVE\u SNPRINTF”,
“/DLIBCARLA_带有PYTHON_支持”,“-DLIBCARLA_IMAGE_带有PNG_支持=true”]
其他:
引发未实现的错误
dependens=[x代表行走中的x('source/libcarla')]
依赖项+=[x代表行走中的x('dependencies')]
def make_扩展名(名称、来源):
返回分机(
名称
来源=来源,
include_dirs=include_dirs,
库目录=库目录,
图书馆=图书馆,
额外编译参数=额外编译参数,
额外链接参数=额外链接参数,
language='c++14',
依赖=依赖)
打印('正在编译:\n-%s'%\n-'。加入(源))
return[make_extension('carla.libcarla',sources)]
设置(
name='carla',
version='0.9.8',
包_dir={'':'source'},
套餐=['carla'],
E
#include "carla/trafficmanager/MPC.h"
#include <cppad/cppad.hpp>
#include <cppad/ipopt/solve.hpp>
#include <Eigen-3.3/Eigen/Dense>
#include <vector>
#include <Eigen-3.3/Eigen/Dense>

#include "carla/trafficmanager/PIDController.h"
#include "carla/client/Vehicle.h"
#include "carla/geom/Math.h"