简而言之,我想启动一个附带项目,我需要制作我的代码的 .exe
。我设法但是,每当我尝试单击它时都会出现错误:
此应用程序无法在您的PC上运行
正常终端可完美地运行可执行文件。
我已经知道这是一个路径问题,几天我一直在寻找答案。我只是不知道路径问题是什么或如何使%.exe
包括其路径,因此可以单击。
我认为问题不在实际代码中,但我仍然会在此处包含我的makefile的快照:
.Phony: all server dist clean
IDIR = include
CC ?= gcc
USERFLAGS+=
CLFLAGS += -I$(IDIR) -g -Wall -Wpedantic $(USERFLAGS) -std=c11 -Wno-format-extra-args
ODIR=obj
LDIR=lib
SRCDIR=src
LIBS=-lm
SRCS= $(wildcard $(SRCDIR)/*.c)
DEPS= $(wildcard $(ODIR)/*.o)
OBJ = $(patsubst $(SRCDIR)/%, $(ODIR)/%, $(SRCS:%.c=%.o))
all: server.exe
$(ODIR)/%.o: $(SRCDIR)/%.c
@echo "Making objects..."
mkdir -p $(ODIR)
$(CC) -MMD $(CLFLAGS) -c -o $@ $<
server.exe: $(OBJ)
@echo "Compiling..."
$(CC) -o $@ $(OBJ) $(CFLAGS) $(LIBS)
正常模式下的主要错误消息:
此应用程序无法在此PC上运行
管理模式的错误消息:
Windows找不到" []/[]/server.exe",请确保您输入 正确名称。
我只是不知道在哪里设置路径或如何自动化该路径。
解释肯定是二进制文件与GCC安装目录中的DLL链接。
识别二进制链接的DLL的最简单方法是执行strings server.exe | find /i ".dll"
。
没有strings.exe?请参阅此问题:https://superuser.com/questions/124081/is-there-a-a-windows-equivalent-of-the-unix-strings-command-command
以下提出的makefile:
- 应产生所需的输出
- 启用警告,以便将用户告知编译问题
现在提出的makefile:
OBJDIR := obj
LIBDIR := lib
SRCDIR := src
INCDIR := include
NAME := server.exe
SHELL := /bin/sh
CC := gcc
DEBUG := -ggdb3
CFLAGS := $(DEBUG) -Wall -Wextra -pedantic -Wconversion -std=c11
MAKE := /usr/bin/make
CC := /usr/bin/gcc
LFLAGS := -L/usr/local/lib
LIBS := -lm
.PHONY: all
all : $(NAME)
#
# macro of all *.c files
# (NOTE:
# (the following 'wildcard' will pick up ALL .c files in the source directory
SRC := $(wildcard $(SRCDIR)/*.c)
OBJ := $(SRC:.c=.o)
DEP := $(SRC:.c=.d)
#
# link the .o files into the executable
# using the linker flags
# -- explicit rule
#
%(LIBDIR)/$(NAME): $(OBJDIR)/$(OBJ)
#
# ======= $(NAME) Link Start =========
@echo "linking into executable..."
$(CC) -o $@ $^ $(LFLAGS) $(LIBS)
# ======= $(NAME) Link Done ==========
#
#
#create dependency files
%.d: %.c
#
# ========= START $< TO $@ =========
@echo "Making dependencies..."
$(CC) -MMD $(CFLAGS) -c -o $@ $<
# ========= END $< TO $@ =========
#
# compile the .c file into .o files using the compiler flags
#
%.o: %.c %.d
#
# ========= START $< TO $@ =========
@echo "Making objects..."
$(CC) $(CFLAGS) -c $< -o $@ -I$(INCDIR)
# ========= END $< TO $@ =========
#
.PHONY: clean
clean:
# ========== CLEANING UP ==========
rm -f $(OBJDIR)/*.o
rm -f $(name)
rm -f *.d
# ========== DONE ==========
# include the contents of all the .d files
# note: the .d files contain:
# <filename>.o:<filename>.c plus all the dependencies for that .c file
# I.E. the #include'd header files
# wrap with ifneg... so will not rebuild *.d files when goal is 'clean'
#
ifneq "$(MAKECMDGOALS)" "clean"
-include $(DEP)
endif