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 6899393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:24:58+00:00 2026-05-27T07:24:58+00:00

I have a file Cache.cpp that has a corresponding header file Cache.h and another

  • 0

I have a file Cache.cpp that has a corresponding header file Cache.h and another NetFunctions.cpp that has a corresponding header file NetFunction.h.

I have a makefile that looks like this

all: net cache
    g++ main.cpp ../obj/NetFunctions.o ../obj/Cache.o -o ../bin/main
net: NetFunctions.cpp
    g++ -c NetFunctions.cpp -o ../obj/NetFunctions.o
cache: Cache.cpp net
    g++ -c Cache.cpp ../obj/NetFunctions.o -o ../obj/Cache.o

Now NetFunctions.cpp has a function getNFHTML(string) defined there, which is used in Cache.cpp. I have checked the header files and they look fine with all the functions, declared there and header files properly included.

However, when I make, I get the following linker error

../obj/Cache.o: In function `Cache::getHTML(std::basic_string<char,  std::char_traits<char>, std::allocator<char> >)':
Cache.cpp:(.text+0x19ee): undefined reference to `getNFHTML(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status
make: *** [test] Error 1***

Can someone help me with this? What is the problem?

I have also referred to this post C++ Linking error, but it was of no help to me.

Edit

Here is the code:
NetFunctions.h

#ifndef NET
#define NET 1

#include "commons.h"

bool serv_bind(struct addrinfo **servinfo, struct addrinfo **p, int *sockfd, int *yes);
void* get_in_addr(struct sockaddr *sa);
string getNFHTML(string website);  
string saveHeaders(string);
//bool getNFHTML(string request, string last_modified, string *response);
extern bool useCache;

#endif

NetFunctions.cpp

    #include "NetFunctions.h"
    string getNFHTML(string request)
    {
    // a lot of code
    }

Cache.cpp

#include "NetFunctions.h"
#include "Cache.h"
string Cache::getHTML(string request)
{
//some code
    string response = getNFHTML(request);
//some code
}

I have stripped the files as they contained several hundred lines

  • 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-27T07:24:59+00:00Added an answer on May 27, 2026 at 7:24 am

    This has nothing to do with the problem, but I put it in an answer so it will be better formated.

    Your makefile doesn’t handle dependencies very well. Try this one instead:

    .PHONY: all
    all: ../bin/main
    
    ../bin/main: main.cpp ../obj/NetFunctions.o ../obj/Cache.o
        g++ $^ -o $@
    
    ../obj/NetFunctions.o: NetFunctions.cpp
        g++ -c $< -o $@
    
    ../obj/Cache.o: Cache.cpp 
        g++ -c $< -o $@
    

    For the ../bin/main target, the variable $^ means to take all prerequisites, and $@ is the target of the rule. This means you can add as many object files as you like, and all will be linked.

    For the compilation of the source to object files, the $< variable is the first prerequisite. This will also make it easier to copy/paste the targets if you add more files.

    The rules also make sure that when you build ../bin/main all files it depends on will be built properly.

    The first target, all, will be the default if you run make without specifying a target. It has been marked as a phony target, because it doesn’t produce a file called all.

    Note that I’m basing this on GNU make, which is standard in almost all Linux distributions, and in Cygwin/MingW. If you use BSD make the variables might change.

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

Sidebar

Related Questions

I have found this code to make php file cache and compress. Below is
I have a jar file with resources (mainly configuration for caches, logging, etc) that
In the filesystem I have /file.aspx /directory/default.aspx I want to configure IIS so that
I have a variable in code that can have file path or url as
I have a file that I want to include in Python but the included
I currently have a distributed cache using EHCache via RMI that works just fine.
I have a file that goes thru a large data set and splits out
I have designed a stylesheet/javascript files bundler and minifier that uses a simple cache
I have intersystem cache database file (cache.dat around 160MB). From management portal, I created
I have a file which is an XML representation of some data that is

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.