Linking starts before any compilation resulting in undefined reference to main function.
techie-guy opened this issue · comments
What seems to be the problem?
Linking starts before any compilation resulting in undefined reference to main function. This problem occurs only If I use the Native
platform. It works fine for the Web
platform.
The output:
On Running make config=debug_native
==== Building test-app (debug_native) ====
Creating bin/Debug-Native/test-app
Linking test-app
clang: error: no input files
make[1]: *** [test-app.make:183: bin/Debug-Native/test-app/test-app] Error 1
make: *** [Makefile:36: test-app] Error 2
On Running make config=debug_web
==== Building test-app (debug_web) ====
Creating bin/Debug-Web/test-app/obj
main.c
Linking test-app
What did you expect to happen?
Compilation of the source files should happen first...
What have you tried so far?
...
How can we reproduce this?
The premake5 script. I am using the emscripten module
require("emscripten")
workspace "test-app"
startproject "test-app"
configurations { "Debug", "Release" }
platforms { "Native", "Web" }
filter { "platforms:Native" }
toolset "clang"
filter { "platforms:Web" }
toolset "emcc"
outputdir = "%{cfg.buildcfg}-%{cfg.platform}"
project "test-app"
kind "ConsoleApp"
language "C"
targetdir "bin/%{outputdir}/%{prj.name}"
objdir "bin/%{outputdir}/%{prj.name}/obj"
location "."
filter { "platforms:Native" }
defines
{
"_PLATFORM_NATIVE"
}
filter { "platforms:Web" }
targetextension ".html"
defines
{
"_PLATFORM_WEB"
}
files
{
"main.c",
}
filter "configurations:Debug"
defines { "DEBUG" }
symbols "On"
filter "configurations:Release"
defines { "NDEBUG" }
optimize "On"
- Visual Studio 2022 (vs2022)
- Visual Studio 2019 (vs2019)
- Visual Studio 2017 (vs2017)
- Visual Studio 2015 (vs2015)
- Visual Studio 2012 (vs2012)
- Visual Studio 2010 (vs2010)
- Visual Studio 2008 (vs2008)
- Visual Studio 2005 (vs2005)
- GNU Makefile (gmake)
- GNU Makefile 2 (gmake2)
- XCode (xcode)
- Codelite
- Other (Please list below)
What version of Premake are you using?
premake5 (Premake Build Script Generator) 5.0.0-dev
Can you share the generated makefile?
I have updated the premake5 script as the earlier one didn't reproduce the issue
Also here's the generated test-app.make
# Alternative GNU Make project makefile autogenerated by Premake
ifndef config
config=debug_native
endif
ifndef verbose
SILENT = @
endif
.PHONY: clean prebuild
SHELLTYPE := posix
ifeq (.exe,$(findstring .exe,$(ComSpec)))
SHELLTYPE := msdos
endif
# Configurations
# #############################################
INCLUDES +=
FORCE_INCLUDE +=
ALL_CPPFLAGS += $(CPPFLAGS) -MD -MP $(DEFINES) $(INCLUDES)
ALL_RESFLAGS += $(RESFLAGS) $(DEFINES) $(INCLUDES)
LIBS +=
LDDEPS +=
ALL_LDFLAGS += $(LDFLAGS)
LINKCMD = $(CC) -o "$@" $(OBJECTS) $(RESOURCES) $(ALL_LDFLAGS) $(LIBS)
define PREBUILDCMDS
endef
define PRELINKCMDS
endef
define POSTBUILDCMDS
endef
ifeq ($(config),debug_native)
ifeq ($(origin CC), default)
CC = clang
endif
ifeq ($(origin CXX), default)
CXX = clang++
endif
ifeq ($(origin AR), default)
AR = ar
endif
TARGETDIR = bin/Debug-Native/test-app
TARGET = $(TARGETDIR)/test-app
OBJDIR = bin/Debug-Native/test-app/obj
DEFINES += -D_PLATFORM_NATIVE -DDEBUG
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g
else ifeq ($(config),debug_web)
ifeq ($(origin CC), default)
CC = emcc
endif
ifeq ($(origin CXX), default)
CXX = em++
endif
ifeq ($(origin AR), default)
AR = emar
endif
TARGETDIR = bin/Debug-Web/test-app
TARGET = $(TARGETDIR)/test-app.html
OBJDIR = bin/Debug-Web/test-app/obj
DEFINES += -D_PLATFORM_WEB -DDEBUG
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -g
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -g
else ifeq ($(config),release_native)
ifeq ($(origin CC), default)
CC = clang
endif
ifeq ($(origin CXX), default)
CXX = clang++
endif
ifeq ($(origin AR), default)
AR = ar
endif
TARGETDIR = bin/Release-Native/test-app
TARGET = $(TARGETDIR)/test-app
OBJDIR = bin/Release-Native/test-app/obj
DEFINES += -D_PLATFORM_NATIVE -DNDEBUG
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2
else ifeq ($(config),release_web)
ifeq ($(origin CC), default)
CC = emcc
endif
ifeq ($(origin CXX), default)
CXX = em++
endif
ifeq ($(origin AR), default)
AR = emar
endif
TARGETDIR = bin/Release-Web/test-app
TARGET = $(TARGETDIR)/test-app.html
OBJDIR = bin/Release-Web/test-app/obj
DEFINES += -D_PLATFORM_WEB -DNDEBUG
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -O2
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -O2
endif
# Per File Configurations
# #############################################
# File sets
# #############################################
GENERATED :=
OBJECTS :=
ifeq ($(config),debug_web)
GENERATED += $(OBJDIR)/main.o
OBJECTS += $(OBJDIR)/main.o
else ifeq ($(config),release_web)
GENERATED += $(OBJDIR)/main.o
OBJECTS += $(OBJDIR)/main.o
endif
# Rules
# #############################################
all: $(TARGET)
@:
$(TARGETDIR):
@echo Creating $(TARGETDIR)
ifeq (posix,$(SHELLTYPE))
$(SILENT) mkdir -p $(TARGETDIR)
else
$(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
endif
$(OBJDIR):
@echo Creating $(OBJDIR)
ifeq (posix,$(SHELLTYPE))
$(SILENT) mkdir -p $(OBJDIR)
else
$(SILENT) mkdir $(subst /,\\,$(OBJDIR))
endif
clean:
@echo Cleaning test-app
ifeq (posix,$(SHELLTYPE))
$(SILENT) rm -f $(TARGET)
$(SILENT) rm -rf $(GENERATED)
$(SILENT) rm -rf $(OBJDIR)
else
$(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
$(SILENT) if exist $(subst /,\\,$(GENERATED)) del /s /q $(subst /,\\,$(GENERATED))
$(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
endif
prebuild: | $(OBJDIR)
$(PREBUILDCMDS)
ifneq (,$(PCH))
$(OBJECTS): $(GCH) | $(PCH_PLACEHOLDER)
$(GCH): $(PCH) | prebuild
@echo $(notdir $<)
$(SILENT) $(CC) -x c-header $(ALL_CFLAGS) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
$(PCH_PLACEHOLDER): $(GCH) | $(OBJDIR)
ifeq (posix,$(SHELLTYPE))
$(SILENT) touch "$@"
else
$(SILENT) echo $null >> "$@"
endif
else
$(OBJECTS): | prebuild
endif
ifeq ($(config),debug_native)
$(TARGET): $(OBJECTS) $(LDDEPS) | $(TARGETDIR)
$(PRELINKCMDS)
@echo Linking test-app
$(SILENT) $(LINKCMD)
$(POSTBUILDCMDS)
else ifeq ($(config),debug_web)
$(TARGET): $(GENERATED) $(OBJECTS) $(LDDEPS) | $(TARGETDIR)
$(PRELINKCMDS)
@echo Linking test-app
$(SILENT) $(LINKCMD)
$(POSTBUILDCMDS)
else ifeq ($(config),release_native)
$(TARGET): $(OBJECTS) $(LDDEPS) | $(TARGETDIR)
$(PRELINKCMDS)
@echo Linking test-app
$(SILENT) $(LINKCMD)
$(POSTBUILDCMDS)
else ifeq ($(config),release_web)
$(TARGET): $(GENERATED) $(OBJECTS) $(LDDEPS) | $(TARGETDIR)
$(PRELINKCMDS)
@echo Linking test-app
$(SILENT) $(LINKCMD)
$(POSTBUILDCMDS)
endif
# File Rules
# #############################################
ifeq ($(config),debug_web)
$(OBJDIR)/main.o: main.c
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
else ifeq ($(config),release_web)
$(OBJDIR)/main.o: main.c
@echo "$(notdir $<)"
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
endif
-include $(OBJECTS:%.o=%.d)
ifneq (,$(PCH))
-include $(PCH_PLACEHOLDER).d
endif
You need to close/reset the filter, as the filters affect everything after it. When you're done applying filters, use filter {}
and that should fix it.
Ohh, I see. Thanks for your help!