2016-11-07 36 views
1

我想一個圖標添加到我的exe使用MinGW-GCC編譯EXE。無法添加圖標使用windres

我跟着指令this SO post但是圖標沒有在我的Windows資源管理器的exe露面。

同時我發現windres破壞了我的可執行文件。在應用windres之前,可執行文件按預期運行。在應用windres調用可執行結果的窗口錯誤消息(粗略地)告訴這個可執行文件與此Windows版本不兼容。

我在做什麼錯?


這是我的目錄佈局:

$ ls -lR launcher/ 
launcher/: 
total 508 
drwxr-xr-x 1 me 1049089  0 Aug 20 2015 src/ 
drwxr-xr-x 1 me 1049089  0 Nov 7 10:56 target/ 

launcher/src: 
total 0 
drwxr-xr-x 1 me 1049089 0 Nov 7 10:51 main/ 

launcher/src/main: 
total 4 
drwxr-xr-x 1 me 1049089 0 Nov 7 10:52 cpp/ 
drwxr-xr-x 1 me 1049089 0 Apr 14 2016 resources/ 
drwxr-xr-x 1 me 1049089 0 Nov 4 15:11 scripts/ 

launcher/src/main/cpp: 
total 8 
-rw-r--r-- 1 me 1049089 6793 Nov 7 10:41 JavaLauncher.cpp 

launcher/src/main/resources: 
total 5 
-rw-r--r-- 1 me 1049089 47 Nov 7 10:47 javaLauncher.rc 
-rw-r--r-- 1 me 1049089 2238 Apr 14 2016 JavaLauncher.ico 

launcher/src/main/scripts: 
total 1 
-rw-r--r-- 1 me 1049089 389 Nov 7 10:56 makefile 

launcher/target: 
total 4 
-rwxr-xr-x 1 me 1049089 2502 Nov 7 10:56 JavaLauncher.exe* 

這是我的資源文件:

0 ICON "launcher/src/main/resources/JavaLauncher.ico" 

這是我的makefile:

all: launcher/target/JavaLauncher.exe 

launcher/target/JavaLauncher.exe: launcher/src/main/cpp/JavaLauncher.cpp launcher\target 
    /Absolute/Path/to/mingw64/bin/g++.exe $< -o [email protected] -static -l winpthread 
    /Absolute/Path/to/mingw64/bin/windres.exe -v -i launcher/src/main/resources/javaLauncher.rc -o [email protected] 


launcher\target: 
    cmd /c md [email protected] 

這是輸出使:

/Project/root>/Absolute/Path/to/mingw64\bin\make.exe -f launcher\src\main\scripts\makefile 
cmd /c md launcher\target 
/Absolute/Path/to/mingw64/bin/g++.exe launcher/src/main/cpp/JavaLauncher.cpp -o launcher/target/JavaLauncher.exe -static -l winpthread 
/Absolute/Path/to/mingw64/bin/windres.exe -v -i launcher/src/main/resources/javaLauncher.rc -o launcher/target/JavaLauncher.exe 
Using `/Absolute/Path/to/mingw64/bin/gcc -E -xc -DRC_INVOKED launcher/src/main/resources/javaLauncher.rc' 
Using popen to read preprocessor output 

/Project/root> 

這是結果在Windows資源管理器: exe without specified image


[編輯] 最終的工作液是這樣的:

mingwPath = $(realpath Path/to/mingw64/bin) 
TARGET_DIR=target 
TARGET_OBJECT_DIR=$(TARGET_DIR)/objects 
TARGET_DIR_NAME=$(subst /,\, $(TARGET_DIR)) 
TARGET_OBJECT_DIR_NAME=$(subst /,\, $(TARGET_OBJECT_DIR)) 
SOURCE_DIR_NAME=src/main 
APP_NAME=MyApp 
TARGET_BASE_NAME=$(TARGET_DIR)/$(APP_NAME) 
TARGET_ARCH=-m32 

all: $(TARGET_OBJECT_DIR_NAME) $(TARGET_BASE_NAME).exe 


$(TARGET_BASE_NAME).exe: $(TARGET_OBJECT_DIR)/$(APP_NAME).o\ 
$(TARGET_OBJECT_DIR)/$(APP_NAME)Res.o $(TARGET_OBJECT_DIR_NAME)  
    $(mingwPath)/g++ $(TARGET_ARCH) -o [email protected] -static -l winpthread $(filter %.o,$^) 

$(TARGET_OBJECT_DIR)/$(APP_NAME).o: $(SOURCE_DIR_NAME)/cpp/$(APP_NAME).cpp 
    $(mingwPath)/g++ $(TARGET_ARCH) -c $< -o [email protected] 

$(TARGET_OBJECT_DIR)/$(APP_NAME)Res.o: $(SOURCE_DIR_NAME)/resources/$(APP_NAME).rc 
    $(mingwPath)/windres -v -i $< -o [email protected] --output-format=coff --target=pe-i386 


$(TARGET_OBJECT_DIR_NAME):$(TARGET_DIR_NAME) 
    echo [email protected] 
    cmd /c md [email protected] 

$(TARGET_DIR_NAME): 
    echo [email protected] 
    cmd /c md [email protected] 

clean: 
    cmd /c del /s /q $(TARGET_DIR_NAME) 

回答

1

我不知道,如果資源編譯器windres可以將資源數據直接編譯並添加到exe文件中,但這就是y你試圖在這裏做。也許這是可能的,我搜索了一下,但沒有找到有關信息。

我得到了這個工作並具有exe文件圖標。您需要在程序對象之後指定windres生成的資源對象與g++鏈接器。也改變了順序,首先必須windres跑這麼有產生的資源對象文件之前g++鏈接鏈接程序和資源對象。

all: launcher/target/JavaLauncher.exe 

launcher/target/JavaLauncher.exe: launcher/src/main/cpp/JavaLauncher.cpp launcher\target 
    /Absolute/Path/to/mingw64/bin/windres.exe -v -i launcher/src/main/resources/JavaLauncher.rc -o launcher/src/main/resources/JavaLauncherRes.o 
    /Absolute/Path/to/mingw64/bin/g++.exe $< -o [email protected] launcher/src/main/resources/JavaLauncherRes.o -static 


launcher\target: 
    cmd /c md [email protected] 

enter image description here

+0

仍無法證實,因爲現在我跑進32位目標的問題。在這裏看到:http://stackoverflow.com/questions/40584265/undefined-reference-to-winmain16-after-applying-windes –

+0

你嘗試,我告訴你,要改變windres秩序和目標文件,它產生?然後添加目標文件的G ++鏈接分辯了'-o $ @後' –

+0

是的,新make文件現在首先建立在其上windres添加圖標的* .o文件將。這是我從你的答案中得到的。 –