Make 无法识别我的图书馆!

Make is not recognizing my library!

我正在尝试用 C++ 创建一个使用 rudeconfig 库的程序。

我运行制作并得到这个:

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

我知道发生这种情况是因为 make 无法识别 rudeconfig 库,但是我已按照 rudeconfig 站点上的说明正确安装。

代码如下:

生成文件

#
# 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[ :]*,.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;}
}

错误是由这条命令引起的:

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

不是 make 本身。

该错误表示链接器未在库搜索路径中找到 librudeconfig.so。根据您的评论,结果是该库被命名为 rudeconfig.so,因此您需要指定

LDLIBS = -l:rudeconfig.so

而不是 -lrudeconfig(它总是扩展为 librudeconfig.solibrudeconfig.a)。

理想情况下,库应该安装为 librudeconfig.so...