2

In a nutshell, I want to start a side project and I need to make .exe of my code. I manage to but whenever I try to click it gives the error:

This app can't run on your pc

The normal terminal runs the executable perfectly.

I already know it is a PATH problem and I have been looking for an answer for a couple of days now. I just do not know what the PATH problem is or how to make the %.exe to include its path so it is clickable.

I think the problem is not in the actual code but I will still include a snapshot of my Makefile here:

.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)

The main error message in normal mode:

This app cannot run on this pc

Error message in administrative mode:

Windows cannot find "[]/[]/server.exe", make sure you typed in the name correctly.

And I just do not know where to set the path or how to automate that, if possible.

Eduardo Baitello
  • 10,469
  • 7
  • 46
  • 74
Xidot
  • 21
  • 2
  • What `gcc -v` is telling you? – Eugene Sh. Jul 04 '19 at 17:40
  • What is this: `CC ?= gcc` I would expect that to be: `CC := gcc` – user3629249 Jul 04 '19 at 17:47
  • Hm. Does it even create the executable? – Eugene Sh. Jul 04 '19 at 17:47
  • regarding; `DEPS= $(wildcard $(ODIR)/*.o)` Usually the dependencies are related to the header files, not the object files – user3629249 Jul 04 '19 at 17:50
  • regarding this kind of statement: `SRCS= $(wildcard $(SRCDIR)/*.c)` The use of `=` results in the macro being re-evaluated every time it is referenced. Much better to use: `:=` which results in the macro only being evaluated once – user3629249 Jul 04 '19 at 17:52
  • regarding: `$(ODIR)/%.o: $(SRCDIR)/%.c @echo "Making objects..." mkdir -p $(ODIR) $(CC) -MMD $(CLFLAGS) -c -o $@ $<` This is trying to produce dependency files (which normally have a `.d` suffix) however, the first line of this rule is forcing files that have a `.o` suffix. This is a problem – user3629249 Jul 04 '19 at 18:21
  • @EugeneSh. it compiles i linked screenshot. https://imgur.com/a/u2aMaSH – Xidot Jul 04 '19 at 19:19
  • @user3629249 the verbose mode for main.c, https://imgur.com/a/u2aMaSH – Xidot Jul 04 '19 at 19:20
  • 1
    So.. your `gcc` target is Linux. How do you expect it to run on windows? – Eugene Sh. Jul 04 '19 at 19:22
  • where did your makefile place the executable: `server.exe`? In general, that is where you need to run to `server.exe` application from – user3629249 Jul 04 '19 at 19:36
  • My server.exe is placed in the dir specified which is the location where the Makefile is, so in other words in where the screenshot shows it. i was using ```cc``` and just tried ```gcc``` as my last trial. Both work if run from terminal. – Xidot Jul 04 '19 at 20:06
  • @user3629249 i have changed to cmake which makes the executable clickable, but i really do not understand what i am missing, to be honest. – Xidot Jul 05 '19 at 20:29

2 Answers2

0

The explanation is certainly the binary is linked against a DLL in GCC's installation directory.

The easiest way to identify what dlls the binary is linked against is to do strings server.exe | find /i ".dll".

Don't have a strings.exe? See this question: https://superuser.com/questions/124081/is-there-a-windows-equivalent-of-the-unix-strings-command

Joshua
  • 40,822
  • 8
  • 72
  • 132
  • It errors with: unknown predicate "-i". For clarification, you think the problem is that the DLL is not being linked? – Xidot Jul 04 '19 at 19:51
  • @Xidot: It's /i not -i. My bad. What I think happened is there's a dll that gcc links against that's in gcc's bin directory. So you have to copy it around to use the binary. – Joshua Jul 04 '19 at 20:02
  • Bad news, /i not found; good news: i now know /i doesnt exist! And i am not quite sure what to do with that. – Xidot Jul 04 '19 at 20:51
  • https://ss64.com/nt/find.html and many others say otherwise; therefore I think you're picking up find from msys. If you have all of msys in your path you can replace `find /i` with `grep -i` – Joshua Jul 04 '19 at 21:05
0

the following proposed Makefile:

  1. should produce the desired output
  2. enables warnings, so the user will be informed of compile problems

and now the proposed 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
user3629249
  • 16,402
  • 1
  • 16
  • 17