ming window 交叉编译_在Linux上与MinGW交叉编译C ++代码,目标是Windows:发生错误

在Linux环境下使用mingw32编译目标为Windows的C++代码时,遇到了找不到fltk-config --cxxflags和--ldflags文件的错误。通过将backticks替换为$()并创建脚本来获取这些标志,解决了编译错误。然而,现在出现了新的链接错误,找不到-lXext库。
摘要由CSDN通过智能技术生成

At first, I compiled the following code with g++ (actually 'fltk-config --compile') and the executable works fine on Linux. But when I try to compile the code with 'mingw32' on Linux targeting Windows, I run into errors:

#include

#include

#include

int main(int argc,char**argv){

Fl_Window*Fl_Window_Ptr=new Fl_Window(400*1.618,400,"My second window");

Fl_Window_Ptr->begin();

Fl_Button*Fl_Button_Ptr=new Fl_Button(10,400-40,30*1.618,30,"Hi, I mean, hello world!");

Fl_Window_Ptr->end();

Fl_Window_Ptr->show();

return Fl::run();

}

When I try to compile with 'mingw32' like this:

user@computer:~/Documents$ i586-mingw32msvc-g++ 'fltk-config --cxxflags' 2016_02_06a_1st_Window.cxx 'fltk-config --ldflags' -o 2016_02_06a_1st_Window.exe

This error happens:

i586-mingw32msvc-g++: fltk-config --cxxflags: No such file or directory

i586-mingw32msvc-g++: fltk-config --ldflags: No such file or directory

2016_02_06a_1st_Window.cxx:1:19: error: FL/Fl.H: No such file or directory

2016_02_06a_1st_Window.cxx:2:26: error: FL/Fl_Window.H: No such file or directory

2016_02_06a_1st_Window.cxx:3:26: error: FL/Fl_Button.H: No such file or directory

However, just to mention, the following command is fine and executable works in Linux environment:

user@computer:~/Documents$ fltk-config --compile 2016_02_06a_1st_Window.cxx

I was inspired by this post.

解决方案

As "Ulrich Eckhardt" commented, the solution is to modify backticks usage. Finally, the following shell script resolved the previous error:

#! /bin/bash

#This script compiles C++ source codes with MinGW32 with FLTK compile/link flags

echo "Getting fltk-config --cxxflags.."

fltk_config_cxxflags=$(fltk-config --cxxflags)

echo "Getting fltk-config --ldflags.."

fltk_config_ldflags=$(fltk-config --ldflags)

#echo $fltk_config_cxxflags

#echo $fltk_config_ldflags

cxx_source="2016_02_06a_1st_Window.cxx"

exe_output="2016_02_06a_1st_Window.exe"

echo "i586-mingw32msvc-g++ $fltk_config_cxxflags $cxx_source $fltk_config_ldflags -o $exe_output"

echo "Compiling and linking.."

i586-mingw32msvc-g++ $fltk_config_cxxflags $cxx_source $fltk_config_ldflags -o $exe_output

echo "End of script"

The previous error is resolved now, however, I run into a new error of cannot find -lXext which can be seen among terminal output:

user@computer:~/Documents$ ./2016_02_07a_script.sh

Getting fltk-config --cxxflags..

Getting fltk-config --ldflags..

i586-mingw32msvc-g++ -I/usr/local/include -I/usr/local/include/FL/images -I/usr/include/freetype2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_THREAD_SAFE -D_REENTRANT 2016_02_06a_1st_Window.cxx -L/usr/local/lib -lfltk -lXext -lXft -lfontconfig -lpthread -ldl -lm -lX11 -o 2016_02_06a_1st_Window.exe

Compiling and linking..

/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/bin/ld: cannot find -lXext

collect2: ld returned 1 exit status

End of script

Now I'm trying to resolve the new error!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值