Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 819209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:16:20+00:00 2026-05-15T02:16:20+00:00

I’ve started working with my first makefile. I’m writing a roguelike in C++ using

  • 0

I’ve started working with my first makefile. I’m writing a roguelike in C++ using the libtcod library, and have the following hello world program to test if my environment’s up and running:

#include "libtcod.hpp"

int main()
{
    TCODConsole::initRoot(80, 50, "PartyHack");
    TCODConsole::root->printCenter(40, 25, TCOD_BKGND_NONE, "Hello World");
    TCODConsole::flush();
    TCODConsole::waitForKeypress(true);
}

My project directory structure looks like this:

/CppPartyHack  
----/libtcod-1.5.1 # this is the libtcod root folder  
--------/include  
------------libtcod.hpp  
----/PartyHack  
--------makefile  
--------partyhack.cpp # the above code  

(while we’re here, how do I do proper indentation? Using those dashes is silly.)

and here’s my makefile:


SRCDIR = .
INCDIR = ../libtcod-1.5.1/include
CFLAGS = $(FLAGS) -I$(INCDIR) -I$(SRCDIR) -Wall
CC = gcc
CPP = g++
.SUFFIXES: .o .h .c .hpp .cpp

$(TEMP)/%.o : $(SRCDIR)/%.cpp $(CPP) $(CFLAGS) -o $@ -c $< $(TEMP)/%.o : $(SRCDIR)/%.c $(CC) $(CFLAGS) -o $@ -c $<

CPP_OBJS = $(TEMP)partyhack.o

all : partyhack

partyhack : $(CPP_OBJS) $(CPP) $(CPP_OBJS) -o $@ -L../libtcod-1.5.1 -ltcod -ltcod++ -Wl,-rpath,.

clean : \rm -f $(CPP_OBJS) partyhack

I'm using Ubuntu, and my terminal gives me the following errors:

max@max-desktop:~/Desktop/Development/CppPartyhack/PartyHack$ make
g++ -c -o partyhack.o partyhack.cpp
partyhack.cpp:1:23: error: libtcod.hpp: No such file or directory
partyhack.cpp: In function ‘int main()’:
partyhack.cpp:5: error: ‘TCODConsole’ has not been declared
partyhack.cpp:6: error: ‘TCODConsole’ has not been declared
partyhack.cpp:6: error: ‘TCOD_BKGND_NONE’ was not declared in this scope
partyhack.cpp:7: error: ‘TCODConsole’ has not been declared
partyhack.cpp:8: error: ‘TCODConsole’ has not been declared
make: *** [partyhack.o] Error 1

So obviously, the makefile can't find libtcod.hpp. I've double checked and I'm sure the relative path to libtcod.hpp in INCDIR is correct, but as I'm just starting out with makefiles, I'm uncertain what else could be wrong. My makefile is based off a template that the libtcod designers provided along with the library itself, and while I've looked at a few online makefile tutorials, the code in this makefile is a good bit more complicated than any of the examples the tutorials showed, so I'm assuming I screwed up something basic in the conversion. Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:16:20+00:00Added an answer on May 15, 2026 at 2:16 am

    What happens here, is that

    1) make evaluates the target all, which resolves to partyhack.

    2) make evaluates the target partyhack, which resolves to $(CPP_OBJS)

    3) make evaluates the target $(CPP_OBJS), which resolves to $(TMP)partyhack.o

    4) make evaluates the target $(TMP)partyhack.o which resolves to partyhack.o

    This is because TMP is not defined. Also note that the slash is missing after $(TMP).

    5) make evaluates the target partyhack.o, and applies the implicit rule g++ -c -o partyhack.o partyhack.cpp

    It does not apply the rule you specified, namely $(TEMP)/%.o : $(SRCDIR)/%.cpp because TEMP is not defined, so this evaluates to /partyhack.o : ./partyhack.cpp, and we are not building /partyhack.o because we are not in the root directory.

    6) g++ does not find the include file, because the include directories were not passed to it, because your rule was not applied.

    To fix this:

    First, you need to define TEMP (see Nick Meyers answer).

    TEMP = .
    

    Second, you need to change the definition of CPP_OBJS (as Paul R suggested).

    CPP_OBJS = %(TEMP)/partyhack.o
    

    This will work if you invoke make inside the directory CppPartyHack/PartyHack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.