代码之家  ›  专栏  ›  技术社区  ›  user8659414

Make无法识别我的库!

  •  0
  • user8659414  · 技术社区  · 7 年前

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

    我运行make,得到以下结果:

    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[ :]*,\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)
    

    你好世界抄送

    #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;}
    }
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   Stephen Kitt    7 年前

    此错误是由以下命令引起的:

    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。所以 librudeconfig.a )。

    理想情况下,库应安装为 librudeconfig。所以 。。。