Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何从Linux交叉编译到32位Windows可执行文件_C++_Linux_Windows - Fatal编程技术网

C++ 如何从Linux交叉编译到32位Windows可执行文件

C++ 如何从Linux交叉编译到32位Windows可执行文件,c++,linux,windows,C++,Linux,Windows,对于上下文,我正在尝试使用Linux机器将源代码编译为Windows的32位可执行文件。我正在使用当前的viaapt-get。这是我试图编译的项目。更具体地说,17-02-01zip文件包含我感兴趣的源代码。 我的第一次尝试是在tandem linux下使用Makefile\u ubuntu进行编辑,将gcc与mingw提供的gcc进行交换,并通过将\includes添加到引发错误的.cpp文件来修复出现的标题引用问题。超级黑客。有人能给我指出一条光明的道路吗 下面是我正在使用的makefile

对于上下文,我正在尝试使用Linux机器将源代码编译为Windows的32位可执行文件。我正在使用当前的via
apt-get
。这是我试图编译的项目。更具体地说,
17-02-01
zip文件包含我感兴趣的源代码。 我的第一次尝试是在
tandem linux
下使用
Makefile\u ubuntu
进行编辑,将gcc与
mingw
提供的gcc进行交换,并通过将
\includes
添加到引发错误的
.cpp
文件来修复出现的标题引用问题。超级黑客。有人能给我指出一条光明的道路吗

下面是我正在使用的makefile:

#makefile for c++ programs
#change the name of the executable to use for "any" project

EXECUTABLE = ../bin/tandem.exe
#EXECUTABLE = ../bin/p3.exe
LINKCC = $(CXX)

#CXXFLAGS denotes flags for the C++ compiler

CXX = /usr/bin/i686-w64-mingw32-g++-win32

#uncomment this line if you are using gcc 4.x
CXXFLAGS = -m32 -std=gnu++11
#CXXFLAGS = -w -O2 -DGCC4_3
#CXXFLAGS = -w -O2 -DGCC4_3 -DX_P3

#ubuntu 64 bit version
#LDFLAGS = -L/usr/lib/x86_64-linux-gnu/libexpat.a
LDFLAGS = -lpthread -lm -L/usr/lib/x86_64-linux-gnu/libexpat.a
#LDFLAGS = -lpthread -L/usr/lib -lm -lexpat

SRCS := $(wildcard *.cpp)
OBJS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
DEPS := $(patsubst %.o,%.d,$(OBJS))


all: $(EXECUTABLE)

#define the components of the program, and how to link them
#these components are defined as dependencies; that is they must be up-to-date before the code is linked

$(EXECUTABLE): $(DEPS) $(OBJS)
        $(LINKCC) $(CXXFLAGS) -o $(EXECUTABLE) $(OBJS) $(LDFLAGS)

#specify the dep files depend on the cpp files

%.d: %.cpp
        $(CXX) -M $(CXXFLAGS) $< > $@
        $(CXX) -M $(CXXFLAGS) $< | sed s/\\.o/.d/ > $@



clean:
        -rm $(OBJS) $(EXECUTABLE) $(DEPS) *~

explain:
        @echo "The following info represents the program:"
        @echo "Final exec name: $(EXECUTABLE)"
        @echo "Source files:       $(SRCS)"
        @echo "Object files:       $(OBJS)"
        @echo "Dep files:          $(DEPS)"

depend: $(DEPS)
        @echo "Deps are now up-to-date."

-include $(DEPS)
您正在(错误地)链接
/usr/lib/x86_64-linux-gnu/libexpat.a
,这是一个linux库(格式)。你需要得到它的一些Windows版本

顺便说一句,L/usr/lib/x86_64-linux-gnu/libexpat.a不正确。因为
-L
应该提供一个目录而不是一个库来链接

最后,Windows的最新版本可能对您有用(您将编译一个Linux,大部分是静态链接的可执行文件,它可能在Windows上的命令行上运行)。

您(错误地)链接了
/usr/lib/x86_64-Linux-gnu/libexpat.a
,这是一个Linux库(格式)。你需要得到它的一些Windows版本

顺便说一句,L/usr/lib/x86_64-linux-gnu/libexpat.a不正确。因为
-L
应该提供一个目录而不是一个库来链接


最后,Windows的最新版本可能对您有用(您将编译一个Linux,大部分是静态链接的可执行文件,它可能在Windows上的命令行上运行)。

如果您交叉编译到Windows,则需要链接库的Windows版本,不
/usr/lib/x86_64-linux-gnu/libexpat.a
如果要交叉编译到Windows,则需要链接该库的Windows版本,而不是
/usr/lib/x86_64-linux-gnu/libexpat.a
谢谢。我在Windows源代码下看到一个
libexpat.lib
。那可能是我需要的。我来试试。谢谢。我在Windows源代码下看到一个
libexpat.lib
。那可能是我需要的。我试试看。
sudo make -f Makefile_ubuntu
    /usr/bin/i686-w64-mingw32-g++-win32  -m32 -std=gnu++11  -o ../bin/tandem.exe tandem.o p3mprocess.o saxmzdatahandler.o mspectrumcondition.o masscalc.o mprocess.o mreport.o mscore_tandem.o loadmspectrum.o mplugin.o msequenceserver.o saxtaxhandler.o msequencecollection.o mscore.o mrefine.o xmltaxonomy.o mbiomlreport.o saxtandeminputhandler.o saxhandler.o msequtilities.o base64.o saxmodhandler.o mtermmods.o xmlparameter.o saxsaphandler.o saxmzxmlhandler.o saxmzmlhandler.o mxxcleavage.o p3msequenceserver.o mzid_report.o saxbiomlhandler.o p3.o mpmods.o saxgamlhandler.o stdafx.o MSNumpress.o mpam.o -lpthread -lm -L/usr/lib/x86_64-linux-gnu/libexpat.a 
    saxhandler.o:saxhandler.cpp:(.text+0x100): undefined reference to `XML_ParserCreate'
    saxhandler.o:saxhandler.cpp:(.text+0x11d): undefined reference to `XML_SetUserData'
    saxhandler.o:saxhandler.cpp:(.text+0x13b): undefined reference to `XML_SetElementHandler'
    saxhandler.o:saxhandler.cpp:(.text+0x151): undefined reference to `XML_SetCharacterDataHandler'
    saxhandler.o:saxhandler.cpp:(.text+0x1cf): undefined reference to `XML_ParserFree'
    saxhandler.o:saxhandler.cpp:(.text+0x344): undefined reference to `XML_Parse'
    saxhandler.o:saxhandler.cpp:(.text+0x37f): undefined reference to `XML_Parse'
    saxhandler.o:saxhandler.cpp:(.text+0x3bd): undefined reference to `XML_GetErrorCode'
    saxhandler.o:saxhandler.cpp:(.text+0x3d4): undefined reference to `XML_GetCurrentLineNumber'
    collect2: error: ld returned 1 exit status
    Makefile_ubuntu:33: recipe for target '../bin/tandem.exe' failed
    make: *** [../bin/tandem.exe] Error 1