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

  • SEARCH
  • Home
  • 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 7717155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:48:50+00:00 2026-06-01T02:48:50+00:00

I’m trying to solve an issue with makefile. I have a main.cpp and then

  • 0

I’m trying to solve an issue with makefile.

I have a main.cpp and then addOn.cpp and addOn.hpp.
I’m just trying to do the simple makefile to compile this.

I have:

    main: Main.o Log.o
        g++ -o main Main.o Log.o

    Main.o: main.cpp  Log.hpp
        g++ -c main.cpp

    Log.o: Log.cpp Log.hpp
        g++ -c Log.cpp

But keep getting:

    $ make
    g++ -c main.cpp
    g++ -c Log.cpp
    g++ -o main Main.o Log.o
    Undefined symbols for architecture x86_64:
      "Log::~Log()", referenced from:
          _main in Main.o
      "Log::overallVerboseLvl", referenced from:
          Log::setLevel(int)  in Log.o
          Log::Log()   in Log.o
          Log::Log()   in Log.o
          Log::operator<<(char const*)in Log.o
      "Log::fileName", referenced from:
          Log::setFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)in Log.o
          Log::Log(int)in Log.o
          Log::Log(int)in Log.o
          Log::Log()   in Log.o
          Log::Log()   in Log.o
    ld: symbol(s) not found for architecture x86_64
    collect2: ld returned 1 exit status
    make: *** [main] Error 1

Here are the files
main.cpp

#include <iostream>
#include <string.h>
#include "Log.hpp"

int main(int argc, char *argv[]) {
    Log::setFile("output.log"); 
    Log(Log::LEVEL_INF) << "out and up..."; 
    Log::setLevel(Log::LEVEL_INF); 
    Log(Log::LEVEL_INF) << "another line"; 
    Log(Log::LEVEL_ERR) << "now a number: " << 13; 
    Log(Log::LEVEL_DBG) << "I shall not pass";
    return 0;
}

Log.hpp

#ifndef log_Log_hpp
#define log_Log_hpp
#include <string.h>

class Log{
    private:
        static std::string fileName;
        static int overallVerboseLvl;
        int messageVerboseLvl;
    public:
    static const int LEVEL_INF;
    static const int LEVEL_ERR;
    static const int LEVEL_DBG;

    Log(int verboseLvl);
    Log();
    ~Log();
    std::ostream& operator<<(char const*);
    static void setFile(std::string file);
    static void setLevel(int level);

};


#endif

Log.cpp

#include <iostream>
#include <string.h>
#include "Log.hpp"

const int Log::LEVEL_INF = 0;
const int Log::LEVEL_ERR = 1;
const int Log::LEVEL_DBG = 2;

void Log::setLevel(int level){
    Log::overallVerboseLvl = level;
}

void Log::setFile(std::string fileName ){
    Log::fileName = fileName;
}

Log::Log(){
    Log::fileName = "";
    Log::overallVerboseLvl = Log::LEVEL_DBG;
}

Log::Log(int verboseLvl){
    Log::fileName = "";
    Log::messageVerboseLvl = verboseLvl;
}

std::ostream& Log::operator<<(char const* text){
    if (Log::overallVerboseLvl >= Log::messageVerboseLvl) {
        std::cout << text;
    }     
    return std::cout;
}

What am I doing wrong?

  • 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-06-01T02:48:52+00:00Added an answer on June 1, 2026 at 2:48 am

    You haven’t defined the destructor or the missing static variables. Add one of these:

    Log::~Log() {
    }
    

    The static variables part is kind of unintuitive. You’ve declared them, but haven’t defined them. You can think of it like this – all the compiler knows is that you want to be able to use those variables. But say you include Log.h 100 times. You wouldn’t want the compiler to create 100 copies of the same variables. So you have to give it a place to actually instantiate them. In your Log.cpp file, do this:

    // Note, no 'static' keyword needed (or allowed).
    std::string Log::fileName;
    int Log::overallVerboseLvl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.