0

I'm pulling all my code from my instructor that should be compiling but it seems that my library file is not being linked correctly so the file runs as undefined.

My main file runs in src and looks like this with a lot of unused include statements after the # include <Lib.h> statement.

#include <iostream>
#include <Lib.h>
#include "Lib.h"
#include "../include/Lib.h"
//#include "../lib/libalgos-win.a"

using namespace std;

int main() {
    //you must change/expand this code
    int n = 20;
    //Lib guy = new Lib();
    Lib::algorithmA(n);
    cout << "Successful execution" <<endl;
    return 0;
}

My Lib.h file looks like the following

#ifndef LIBRARY_LIB_H
#define LIBRARY_LIB_H



class Lib {
public:
    static void algorithmA(const int& n);
    static void algorithmB(const int& n);
    static void algorithmC(const int& n);
};


#endif //LIBRARY_LIB_H

In my Cmake file I have the following code:

target_link_libraries(a2-program "${PROJECT_SOURCE_DIR}/lib/libalgos-win.a")

This should, in theory, link the library file to the library I have in lib but instead, I'm getting an error about the reference not being defined. He didn't give more instructions on how to edit the code so I'm completely lost.

zaserman
  • 1
  • 1
  • How does your compiler command line look like? That's the most important information for this quesiton, and you unfortunately missed to post it.# – πάντα ῥεῖ Mar 06 '21 at 20:27
  • Here the problem seems to be a missing declaration of the function (a problem with a header inclusion); if the problem came from the linking, you would get an "unresolved external symbol" or something like that – limserhane Mar 06 '21 at 20:34
  • 2
    Also why do you include 3 different "Lib.h" ? – limserhane Mar 06 '21 at 20:36
  • My IDE switched out terminals on me for some reason so the commands used to get the library didn't work. Thanks for the follow up questions as they actually helped me get to the solution weirdly enough. – zaserman Mar 07 '21 at 22:48

0 Answers0