c - 无法运行已编译的C+Gtk+-3软件

标签 c dll makefile gtk nmake

目前我刚刚用 C 和 GTK + -3 创建了一个小软件,一切都在我的机器上完美运行,但是当我在另一台笔记本电脑上测试该软件时 有几个引用 DLL 库的错误。 第一次尝试时,libglib-2.0-0.dll 库丢失,然后是 libwinpthread-1.dll、libintl-8.dll、libiconv-2.dll 库,每当我添加到丢失的库时,都会出现一个新的丢失库。

我想知道是否有任何方法可以在编译时将库包含在可执行文件中?

我使用 mingw64.exe 进行构建,这是我当前的 makefile:

# Tools
CC=x86_64-w64-mingw32-gcc
LD=x86_64-w64-mingw32-gcc
CFLAGS=--std=c99 --pedantic -Wall -W -Wmissing-prototypes -g
LDFLAGS=
SGTKFLAGS=`pkg-config --cflags gtk+-3.0`
EGTKFLAGS=`pkg-config --libs gtk+-3.0`

# Files
EXEC=text_decoration
HEADERS=model.h view.h controller.h
MODULES=model.c view.c controller.c text_decoration.c
OBJECTS=model.o view.o controller.o text_decoration.o

# Commands
RM=rm
RMFLAGS=-f

# Start point
all:$(EXEC)

# Règle pour la génération de l'exécutable
text_decoration: $(MODULES) $(HEADERS)
    $(CC) $(SGTKFLAGS) -g -o $(EXEC) $(MODULES) $(HEADERS) $(EGTKFLAGS)

clean:
    $(RM) $(RMFLAGS) $(EXEC).exe

有一瞬间我以为这是由于使用make命令编译造成的, 当我尝试使用命令 nmake 时,出现以下错误:

C:\msys64\home\Mooo\a>nmake

Microsoft (R) Program Maintenance Utility Version 14.00.24210.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        x86_64-w64-mingw32-gcc `pkg-config --cflags gtk+-3.0` -g -o text_decoration model.c view.c controller.c text_decoration.c model.h view.h controller.h `pkg-config --libs gtk+-3.0`
x86_64-w64-mingw32-gcc.EXE: error: `pkg-config: No such file or directory
x86_64-w64-mingw32-gcc.EXE: error: gtk+-3.0`: No such file or directory
x86_64-w64-mingw32-gcc.EXE: error: `pkg-config: No such file or directory
x86_64-w64-mingw32-gcc.EXE: error: gtk+-3.0`: No such file or directory
x86_64-w64-mingw32-gcc.EXE: error: unrecognized command line option '--cflags'
x86_64-w64-mingw32-gcc.EXE: error: unrecognized command line option '--libs'
NMAKE : fatal error U1077: 'C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.EXE' : return code '0x1'
Stop.

最佳答案

I'm wondering if there is any way to include the libraries in the executable at compile time?

这意味着静态编译整个 GTK+ 堆栈以生成静态库而不是共享库。我认为那是not really supported也不可取。

如果您使用 MSYS2 (这是安装 GTK+ 3 的首选方法),您可以为其创建一个包,然后将该包及其依赖项(您自己的以及 GTK+ 依赖项)安装在特定位置。安装的结果是您可以重新分发的结果,并且应该是独立的。

请阅读有关 GTK+ application redistristribution on Windows 的博客文章。以 gedit 为例,它拥有这一切。

关于c - 无法运行已编译的C+Gtk+-3软件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48835395/

相关文章:

linux - GNU makefile shell 命令无法正常工作

c - 多维数组索引

c - 为什么我们要为一个int数据的链表分配内存?

c - 从链表中给定位置删除一个元素

c++ - 如何在 win32 DLL 程序中使用 IntelliProtector API

java - 在Java中访问dll文件

c - 结构变量数组中的 mexfunction 变量错误

c# - C# dll 参数中的 pythonnet

c++ - 有哪些 Makefile 生成工具?

makefile - 怎么办 "make <subdir> <target>"?