python如何编译_g++和python.h,如何编译

我用g++编译了一个测试代码,没有任何问题。#include "Python.h"

int main(int argc, char** argv)

{

Py_Initialize();

PyRun_SimpleString("import pylab");

PyRun_SimpleString("pylab.plot(range(5))");

PyRun_SimpleString("pylab.show()");

Py_Exit(0);

}

g++ -o test test.cpp -I/usr/include/python2.7/ -lpython2.7

运行良好。

但当我试图将此代码嵌入到另一个项目中时,它失败了。我真的很困惑。

Makefile如下。CXX=g++

CXXFLAGS=-DIB_USE_STD_STRING -Wall -Wno-switch -g

ROOT_DIR=..

BASE_SRC_DIR=${ROOT_DIR}/PosixSocketClient

INCLUDES=-I${ROOT_DIR}/Shared/ -I${BASE_SRC_DIR} -I/usr/include/python2.7

LIBRARY=-L/usr/lib/python2.7/config

TARGET=eu

$(TARGET):

$(CXX) $(CXXFLAGS) $(INCLUDES) -o EClientSocketBase.o -c $(BASE_SRC_DIR)/EClientSocketBase.cpp

$(CXX) $(CXXFLAGS) $(INCLUDES) -o EPosixClientSocket.o -c $(BASE_SRC_DIR)/EPosixClientSocket.cpp

$(CXX) $(CXXFLAGS) $(INCLUDES) -o PosixTestClient.o -c PosixTestClient.cpp

$(CXX) $(CXXFLAGS) $(INCLUDES) -o Main.o -c Main.cpp

$(CXX) $(LIBRARY) -lpython2.7 -o $@ EClientSocketBase.o EPosixClientSocket.o PosixTestClient.o Main.o

clean:

rm -f $(TARGET) *.o

这个项目编译良好并运行,我所做的唯一更改是在Main.cpp文件中添加测试代码。警告/错误消息显示:In file included from /usr/include/python2.7/Python.h:8:0,

from Main.cpp:15:

/usr/include/python2.7/pyconfig.h:1158:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]

/usr/include/features.h:163:0: note: this is the location of the previous definition

/usr/include/python2.7/pyconfig.h:1180:0: warning: "_XOPEN_SOURCE" redefined [enabled by default]

/usr/include/features.h:165:0: note: this is the location of the previous definition

g++ -L/usr/lib/ -lpython2.7 -ldl -lutil -o eu EClientSocketBase.o EPosixClientSocket.o PosixTestClient.o Main.o

Main.o: In function main':

/home/bbc/TWS/IBJts/cpp/eu-ats/Main.cpp:81: undefined reference toPy_Initialize'

/home/bbc/TWS/IBJts/cpp/eu-ats/Main.cpp:82: undefined reference to PyRun_SimpleStringFlags'

/home/bbc/TWS/IBJts/cpp/eu-ats/Main.cpp:83: undefined reference toPyRun_SimpleStringFlags'

/home/bbc/TWS/IBJts/cpp/eu-ats/Main.cpp:84: undefined reference to PyRun_SimpleStringFlags'

/home/bbc/TWS/IBJts/cpp/eu-ats/Main.cpp:85: undefined reference toPy_Exit'

collect2: ld returned 1 exit status

make: * [eu] Error 1

有什么帮助吗?谢谢您!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值