LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   undefined reference - so I have to edit the Makefile? (https://www.linuxquestions.org/questions/linux-newbie-8/undefined-reference-so-i-have-to-edit-the-makefile-4175526211/)

larryburns 11-22-2014 02:50 PM

undefined reference - so I have to edit the Makefile?
 
I have a large amount of code, so I have tried to only include the relevant parts of the code here

I have a header file called "ASp.h"

Code:

namespace ASP
{
    class ASp
    {
        public:
            ASp();
            ASp(FILE* fp); 
            void T_B_P_N(const char* type, int num);
    }
}

another header file "ms.h"

Code:

bool aSpQ(int argc, char* argv[]);
a cpp file "ms.cpp"


Code:

bool aSpQ(int argc, char* argv[])
{
    if(argc != 7)
    {
        usageASpQ();
        return false;
    }
    FILE* input = fileRead(argv[3]);
    string type = string(argv[4]);
    int num = atoi(argv[5]);
    FILE* output    = fileWrite(argv[6]);
    ASp* asp = new ASp(input);
    asp->T_B_P_N(type.c_str(), num);

    for(int i = 0; i < asp->numtr; i++)
    {
        asp->fs[i]->print(output);
    }
    fclose(input);
    fclose(output);
    return true;
}

Those files compiled with no problems when they were included in another cpp file.

I have another file called "PBL.cpp". This compiled fine before, until I tried to include the files above in PBL.cpp

Code:

#include "ASp/ASp.h"

using namespace ASP;
using namespace std;

//bunch of code

bool aSpQ(char * fname_r, string type, int num, char * fname_q)
{
    FILE* input = fileRead(fname_r);
    FILE* output    = fileWrite(fname_q);

    ASp* asp = new ASp(input);
    asp->T_B_P_N(type.c_str(), num);

    for(int i = 0; i < asp->numtr; i++)
    {
        asp->fs[i]->print(output);
    }
    fclose(input);
    fclose(output);
    return true;
}

When I try to compile this, at the line of

Code:

ASp* asp = new ASp(input);):
in the PBL.cpp file

I get the following errors:
I get errors of undefined reference to ASP::ASp::ASp(_IOFILE*) and undefined reference to ASP::ASp::T_B_P_N(char const*, int)


But
Code:

ASp* asp = new ASp(input);
was written in ASp.cpp and
Code:

ASp::T_B_P_N(char const*, int)
was written in another file

Is there a linkage error? Do I need to make changes in the makefile? How do I get the linker to link against the ASp.cpp file? I am new to using Unix

pan64 11-24-2014 02:51 AM

you need to post how do you compile (the commands you use or the makefile)

jpollard 11-25-2014 08:22 AM

That actually looks like a link error... The library containing the definitions/functions was missing.

larryburns 11-28-2014 03:34 PM

My coworker told me the problem is probably with the directories and libraries that are written in CMakeLists.txt. He tried to help briefly, but now he says that he can't help anymore

I have included the relevant parts of the CMakeLists to see if anyone can help

in /ws/larryburns/cmake/ME/Build/sc/ME/CMakeLists.txt:

Code:

SET(ME_LINK_LIBS
  MEAPI
  InLJ
  InEl
  El
  LJ
  PE
  CP
  GOAFT
  ASp
  LB
  Con
)

SET(ME_LINK_LIBS ${ME_LINK_LIBS}
  Blu
  DPG
  PP
  MEU
  SVD
  VFT
  GFT
  Geo
  Cur
  Con
  BO
  UM
  ${O_LIBRARY}
  l4c
#  GL
#  GLU
)

and in /ws/larryburns/cmake/ME/Build/sc/CMakeLists.txt:

Code:

ADD_SUBDIRECTORY (Ut)
ADD_SUBDIRECTORY (ASp)
ADD_SUBDIRECTORY (LB)
ADD_SUBDIRECTORY (Con)
ADD_SUBDIRECTORY (El)
ADD_SUBDIRECTORY (LJ)
ADD_SUBDIRECTORY (InLJ)
ADD_SUBDIRECTORY (InEl)
ADD_SUBDIRECTORY (MEU)
ADD_SUBDIRECTORY (PE)
ADD_SUBDIRECTORY (GB)
ADD_SUBDIRECTORY (GOAFT)
ADD_SUBDIRECTORY (CP)
ADD_SUBDIRECTORY (MEAPI)
ADD_SUBDIRECTORY (Blu)
ADD_SUBDIRECTORY (DPG)
ADD_SUBDIRECTORY (PP)
ADD_SUBDIRECTORY (UM)
ADD_SUBDIRECTORY (SVD)
ADD_SUBDIRECTORY (VFT)
ADD_SUBDIRECTORY (Geo)
ADD_SUBDIRECTORY (GFT)
ADD_SUBDIRECTORY (Con)
ADD_SUBDIRECTORY (BO)
ADD_SUBDIRECTORY (Cur)
ADD_SUBDIRECTORY (l4c)

As can be seen, even when I add ASp in both CMakeLists as a subdirectory and library, but I still get the undefined reference errors


All times are GMT -5. The time now is 07:56 AM.