user8659414
user8659414

Reputation: 23

Make is not recognizing my library!

I am trying to create a program in C++ that utilizes the rudeconfig library.

I run make, and get this:

g++ -o Homework5_executable helloworld.o -lrudeconfig -L/home/j/je/jea160530/hw5/libs

/bin/ld: cannot find -lrudeconfig
collect2: error: ld returned 1 exit status
make: *** [Homework5_executable] Error 1

I know this is happening because make is not recognizing the rudeconfig library, however I have followed the instructions on the rudeconfig site for install correctly.

Here is the code:

Makefile

#
# Set up info for C++ implicit rule
CXX = g++
CXXFLAGS = -Wall
CPPFLAGS = -I/home/012/j/je/jea160530/hw5/include 

#
# Set up any Linker Flags
LDFLAGS = -L/home/012/j/je/jea160530/hw5/libs

#
# Set up libraries needer for compilation
LDLIBS = -lrudeconfig

#
# We choose the project name. This is used in building the file name for the backup target
PROJECTNAME = JesseAlotto_Homework5

#
# We choose the source files to include and name the output
SRCS = helloworld.cc

#
# We choose the name of the executable to be created
EXEC = Homework5_executable

#
# NORMALLY DON'T NEED TO CHANGE ANYTHING BELOW HERE
# =================================================
#
OBJS = $(SRCS:cc=o)

all: $(EXEC)

clean:
    rm -f $(OBJS) *.d *~ \#* $(EXEC)

Makefile: $(SRCS:.cc=.d)





# Pattern for .d files.
# =====================

%.d:%.cc
    @echo Updating .d Dependency File
    @set -e; rm -f $@; \
    $(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
    sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
    rm -f $@.$$$$



# This is a rule to link the files. Pretty standard
# ================================================


$(EXEC): $(OBJS)
    $(CXX) -o $(EXEC) $(OBJS) $(LDFLAGS) $(LDLIBS)
    @echo Program compiled succesfully!

#
# Backup Target
# =============

backup: clean
    @mkdir -p ~/backups; chmod 700 ~/backups
    @$(eval CURDIRNAME := $(bash pwd))
    @$(eval MKBKUPNAME := ~/backups/$(PROJECTNAME)-$(shell date +'%Y.%m.%d-%H:%M:%S').tar.gz)
    @echo
    @echo Writing Backup file to: $(MKBKUPNAME)
    @echo
    @tar -zcvf $(MKBKUPNAME) ./$(CURDIRNAME)
    @chmod 600 $(MKBKUPNAME)
    @echo
    @echo Done!
    #
# Include the dependency files
# ============================

-include $(SRCS:.cc=.d)

helloworld.cc

#include <string>
#include <iostream>
#include <fstream>
#include <tclap/CmdLine.h>
#include <map>
#include <stdlib.h>
#include <rude/config.h>

using namespace rude;

int main(int argc, char *argv[]){
    std::string nextLine;
    std::map<int, std::string> optionMap;


try{
    std::cout << "hello world!";


    //Command Line Variable
    TCLAP::CmdLine cmd("CS3377.002 Program 5", ' ', "1.0");

    //Switch Args
    TCLAP::SwitchArg daemonSwitch("d", "daemon", "Run in daemon mode (forks to run as a daemon).", cmd, false);

    //Unlabeled Value Args
    TCLAP::UnlabeledValueArg<std::string> infileArg("infile", "The name of the configuration file. Defaults to cs3376dirmond.conf", true, "cs3376dirmond.conf", "config filename", false);

    //Add leftover flags to cmdLine object
    cmd.add(infileArg);

    //Parse the command line
    cmd.parse(argc, argv);

    //Create an enumeratedlist for the mapping
    enum flags {DAEMON, INFILE};

    //Map keys and values to map

    if (daemonSwitch.getValue()){
        optionMap[DAEMON] = "1";
    }
    else{
        optionMap[DAEMON] = "0";
    }
    optionMap[INFILE] = infileArg.getValue();

    //Load input file
    std::ifstream inputFile;
    inputFile.open(optionMap[INFILE].c_str(), std::ios::in);

    if(!inputFile){
        std::cerr << "Error: no input file" << std::endl;
    }







    //============================================PARSE CONFIGURATION FILE==========================
    Config config;
    config.load("cs3376dirmond.conf");





    //==============================================================================================


    inputFile.close();
    return 0;

} catch (TCLAP::ArgException &e) //catch any exceptions
{ std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;}
}

Upvotes: 0

Views: 423

Answers (1)

Stephen Kitt
Stephen Kitt

Reputation: 2881

The error is caused by this command:

g++ -o Homework5_executable helloworld.o -lrudeconfig -L/home/j/je/jea160530/hw5/libs

not by make itself.

The error means that the linker isn’t finding librudeconfig.so in the library search path. From your comments, it turns out the library is named rudeconfig.so instead, so you need to specify

LDLIBS = -l:rudeconfig.so

instead of -lrudeconfig (which always expands to librudeconfig.so or librudeconfig.a).

Ideally, the library should be installed as librudeconfig.so...

Upvotes: 3

Related Questions