jveirasv
jveirasv

Reputation: 171

ECLIPSE makefile for C++ projects -- source directory

In Eclipse platform (Windows 10, MinGW toolchain), I'm trying to create a makefile to compile a project with .cpp and .hpp files.

To do that, I choose to create a new project: File -> (popup) New Project C/C++ -> C/C++ Project => NEXT -> C++ Managed Build => MakefileProject -> Hello World C++ MakefileProject

This example compiles and links perfectly. But I want to move the .cpp file into a src directory, then in the Project Explorer window, over the name of the project, I select to create a "Source Folder", naming it as "src". Then I move the .cpp file inside the directory, and try to build the project without success.

How must I modify the makefile included with this example? I've tried everything but without luck. I get this error:

*19:51:33 **** Incremental Build of configuration Default for project CE_SEP **** make all make: *** No rule to make target CE_SEP.o', needed byCE_SEP.exe'. Stop*

Thanks for your support in advance!

Upvotes: 1

Views: 458

Answers (2)

jveirasv
jveirasv

Reputation: 171

I have solved it. I had written wrongly the name of the file, and I have modified the Makefile adding "src\" before the name of the object an exe file:

CXXFLAGS =  -O2 -g -Wall -fmessage-length=0
OBJS =      src\CE.o
LIBS =
TARGET =    src\CE.exe
$(TARGET):  $(OBJS)
    $(CXX) -o $(TARGET) $(OBJS) $(LIBS)
all:    $(TARGET)
clean:
    rm -f $(OBJS) $(TARGET)

But I rather will learn some of CMake as "jonrobm" suggested me. Thank you again!

Upvotes: 0

jonrobm
jonrobm

Reputation: 731

Stop depending on an IDE. There is an actual "Makefile" that you can go in and edit. You likely just have to modify the path to the source file in the Makefile and/or add another Makefile in the "src" folder.

If you don't know Makefile syntax, google a brief tutorial.

Or save yourself some time in the long run and just learn CMake which is just a scripting type language to write platform-portable build systems -- it will generate Makefiles, MSVC projects, Xcode projects, Ninja build files, etc.

Upvotes: 1

Related Questions