无法在 MSYS2 中使用 minGW64 link GTKmm 3 应用程序:未找到 ustring 构造函数
Can't link GTKmm 3 app with minGW64 ithin MSYS2: ustring constructor not found
我试图在 Windows 上编译我的 GTKmm 3 应用程序。编译期间出现 Glib::ustring 没有构造函数
的错误
Glib:: ustring:: ustring(std::string*)
尽管代码在 Ubuntu 上编译成功。
示例代码:
#include <gtkmm.h>
#include <string>
int main()
{
std::string a("aa");
Glib::ustring b(a);
return 0;
}
编译:
g++ -std=c++14 -c test.cpp `pkg-config gtkmm-3.0 --cflags` && \
g++ test.o `pkg-config --libs gtkmm-3.0`
输出(在 Windows 10 x64,MSYS2 MinGW64 上):
test.o:test.cpp:(.text+0x51): undefined reference to `Glib::ustring::ustring(std::string const&)'
test.o:test.cpp:(.text+0x51): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Glib::ustring::ustring(std::string const&)'
collect2: error: ld returned 1 exit status
Windows:Glib 2.50.3、Glibmm 2.50.0、GCC 5.3.0(MinGW 64 位)
Ubuntu:Glib 2.48.1、Glibmm 2.46.3、GCC 5.4.0
问题是我用错了gcc。
which gcc
表明我使用的是 MSYS2 GCC 而不是 MINGW64 GCC。
通过安装正确的 GCC/MinGW64 解决:pacman -S mingw-w64-x86_64-toolchain
我试图在 Windows 上编译我的 GTKmm 3 应用程序。编译期间出现 Glib::ustring 没有构造函数
的错误 Glib:: ustring:: ustring(std::string*)
尽管代码在 Ubuntu 上编译成功。
示例代码:
#include <gtkmm.h>
#include <string>
int main()
{
std::string a("aa");
Glib::ustring b(a);
return 0;
}
编译:
g++ -std=c++14 -c test.cpp `pkg-config gtkmm-3.0 --cflags` && \
g++ test.o `pkg-config --libs gtkmm-3.0`
输出(在 Windows 10 x64,MSYS2 MinGW64 上):
test.o:test.cpp:(.text+0x51): undefined reference to `Glib::ustring::ustring(std::string const&)'
test.o:test.cpp:(.text+0x51): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Glib::ustring::ustring(std::string const&)'
collect2: error: ld returned 1 exit status
Windows:Glib 2.50.3、Glibmm 2.50.0、GCC 5.3.0(MinGW 64 位)
Ubuntu:Glib 2.48.1、Glibmm 2.46.3、GCC 5.4.0
问题是我用错了gcc。
which gcc
表明我使用的是 MSYS2 GCC 而不是 MINGW64 GCC。
通过安装正确的 GCC/MinGW64 解决:pacman -S mingw-w64-x86_64-toolchain