🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.os.linux.programowanie
Article #72950

C++ opcja -E

#72950
From: RM
Date: Sat, 01 Aug 2020 06:28
101 lines
4044 bytes
Piszę program w C++. Potrzebuję zmodyfikować tak Makefile, żeby zostały 
wygenerowane pliki .i - tzn. chcę użyć opcji -E.
Oto mój Makefile:

#ifeq ($(ARCH),win32)
## Windows with the VC++ compiler
#ObjSuf        = obj
#SrcSuf        = cxx
#ExeSuf        = .exe
#DllSuf        = dll
#OutPutOpt     = -out:
#CXX           = cl
#CXXOPT        = -O2
#CXXOPT        = -Z7
#CXXFLAGS      = $(CXXOPT) -G5 -GR -GX -MD -DWIN32 -D_WINDOWS -nologo \
#                -DVISUAL_CPLUSPLUS -D_X86_=1 -D_DLL
#LD            = link
#LDOPT         = -opt:ref
#LDOPT         = -debug
#LDFLAGS       = $(LDOPT) -pdb:none -nologo
#SOFLAGS       = -DLL

CXX      := -c++ # gcc czy g++?
CXXFLAGS := -Wall -Wextra -Werror -no-pie # -pedantic-errors; add 
"-no-pie" to the CMAKE_CXX_FLAGS
LDFLAGS  := -L/usr/lib -lstdc++ -lstdc++fs -lm # -Lsrc/boost_1_65_0/lib/ 
-lboost_regex-gcc34-mt-d-1_3
BUILD    := ./build
OBJ_DIR  := $(BUILD)/objects
APP_DIR  := $(BUILD)/apps
TARGET   := dirtyphp
INCLUDE  := -Iinclude/ # -I src/boost_1_65_0
SRC      := $(wildcard src/*.cpp)

OBJECTS  := $(SRC:%.cpp=$(OBJ_DIR)/%.o)

all: build $(APP_DIR)/$(TARGET)

$(OBJ_DIR)/%.o: %.cpp
	@mkdir -p $(@D)
	$(CXX) $(CXXFLAGS) $(INCLUDE) -E -c $< -o $@ $(LDFLAGS) >$(OBJ_DIR)/%.i

$(APP_DIR)/$(TARGET): $(OBJECTS)
	@mkdir -p $(@D)
	$(CXX) $(CXXFLAGS) -o $(APP_DIR)/$(TARGET) $^ $(LDFLAGS)

.PHONY: all build clean debug release

build:
	@mkdir -p $(APP_DIR)
	@mkdir -p $(OBJ_DIR)

debug: CXXFLAGS += -DDEBUG -g
debug: all

test: CXXFLAGS += -pg # dodałem dynamic execution profiler
test: all

release: CXXFLAGS += -O2
release: all # production

clean:
	-@rm -rvf $(OBJ_DIR)/*
	-@rm -rvf $(APP_DIR)/*

Próbowałem tak: zmieniłem sekcję:

$(OBJ_DIR)/%.o: %.cpp
	@mkdir -p $(@D)
	$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS)

w następujący sposób:

$(OBJ_DIR)/%.o: %.cpp
	@mkdir -p $(@D)
	$(CXX) $(CXXFLAGS) $(INCLUDE) -E -c $< -o $@ $(LDFLAGS) >$(OBJ_DIR)/%.i

Niestety kompilacja się nie udaje:

c++  -Wall -Wextra -Werror -no-pie  -DDEBUG -g -Iinclude/  -E -c 
src/dirtyphp.cpp -o build/objects/src/dirtyphp.o -L/usr/lib -lstdc++ 
-lstdc++fs -lm  >./build/objects/%.i
c++  -Wall -Wextra -Werror -no-pie  -DDEBUG -g -Iinclude/  -E -c 
src/common.cpp -o build/objects/src/common.o -L/usr/lib -lstdc++ 
-lstdc++fs -lm  >./build/objects/%.i
c++  -Wall -Wextra -Werror -no-pie  -DDEBUG -g -Iinclude/  -E -c 
src/source_file.cpp -o build/objects/src/source_file.o -L/usr/lib 
-lstdc++ -lstdc++fs -lm  >./build/objects/%.i
c++  -Wall -Wextra -Werror -no-pie  -DDEBUG -g -Iinclude/  -E -c 
src/obfuscator.cpp -o build/objects/src/obfuscator.o -L/usr/lib -lstdc++ 
-lstdc++fs -lm  >./build/objects/%.i
c++  -Wall -Wextra -Werror -no-pie  -DDEBUG -g -o ./build/apps/dirtyphp 
build/objects/src/dirtyphp.o build/objects/src/common.o 
build/objects/src/source_file.o build/objects/src/obfuscator.o 
-L/usr/lib -lstdc++ -lstdc++fs -lm
build/objects/src/dirtyphp.o: file not recognized: Nieznany format pliku
collect2: error: ld returned 1 exit status
Makefile:38: recipe for target 'build/apps/dirtyphp' failed
make: [build/apps/dirtyphp] Error 1 (zignorowano)

Proszę o pomoc.
Technical Details
Message-ID: <rg3238$1fogv$1@portraits.wsisiz.edu.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!wsisiz.edu.pl!.POSTED.user-94-254-129-44.play-internet.pl!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!wsisiz.edu.pl!.POSTED.user-94-254-129-44.play-internet.pl!not-for-mail
From: RM <robert_magdziarz@wp.pl>
Newsgroups: pl.comp.os.linux.programowanie
Subject: C++ opcja -E
Date: Sat, 1 Aug 2020 08:28:55 +0200
Organization: http://www.wit.edu.pl
Message-ID: <rg3238$1fogv$1@portraits.wsisiz.edu.pl>
Mime-Version: 1.0
Injection-Date: Sat, 1 Aug 2020 06:28:56 -0000 (UTC)
Injection-Info: portraits.wsisiz.edu.pl; posting-host="user-94-254-129-44.play-internet.pl:94.254.129.44"; logging-data="1565215"; mail-complaints-to="abuse@wsisiz.edu.pl"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1
X-Mozilla-News-Host: news://news.icp.pl:119
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit