LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-22-2014, 03:50 PM   #1
larryburns
LQ Newbie
 
Registered: Nov 2014
Posts: 19

Rep: Reputation: Disabled
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
 
Old 11-24-2014, 03:51 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,879

Rep: Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910
you need to post how do you compile (the commands you use or the makefile)
 
Old 11-25-2014, 09:22 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
That actually looks like a link error... The library containing the definitions/functions was missing.
 
Old 11-28-2014, 04:34 PM   #4
larryburns
LQ Newbie
 
Registered: Nov 2014
Posts: 19

Original Poster
Rep: Reputation: Disabled
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

Last edited by larryburns; 11-28-2014 at 10:57 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ undefined reference grob115 Programming 4 01-22-2013 12:22 PM
Yet another undefined reference CollieJim Linux - General 2 12-18-2010 12:08 AM
Undefined reference to: ashlesha Programming 5 11-08-2006 02:07 PM
undefined reference vkmgeek Programming 1 05-11-2006 07:37 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 04:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration