How do you add libraries to Eclipse CDT? (No such file or directory)

后端 未结 5 2016
梦谈多话
梦谈多话 2021-01-19 12:27

I\'m having some issues adding header libraries.

I right click on my project, and click Properties-> C/C++ General-> Paths and Symbols.

In

相关标签:
5条回答
  • 2021-01-19 12:56

    I right click on my project, and click Properties-> C/C++ General-> Paths and Symbols.

    In the Includes tab: Languages-> GNU C++

    I click on Add... -> File system then add the folder called boost_1_52_0, or any other folder.

    When I use Eclipse's intellisense, it finds the that I desire, however it fails on building.

    Yes, that's what you might need to keep Eclipse CDT intellisense and the indexer in sync with your external references.

    fatal error: boost/random/...: No such file or directory
    

    Not sure why this is happening.

    This is because your settings for how to build the project might choose you're going to manage the build process yourself: CDT C/C++ Build Properties

    If so, you have to let know your manually managed makefile know about the environment and compiler/linker flag settings.

    A way to communicate with the manually managed makefile with the Eclipse CDT build properties for such cases, is to use e.g. Build Variables or Environment settings from the mentioned project property section: enter image description here

    0 讨论(0)
  • 2021-01-19 13:04

    What to add depends on what you are trying to include. In the case of Boost, there are a number of header-only libraries, and there are some libraries that require linking in static/shared-object libraries (e.g., serialization).

    Header-Only Libraries

    For header-only libraries, you just need to include the base directory of all the header files. With gcc, you add the directory using the -I flag (e.g., -I C:/path/to/boost_52_0). With a managed makefile project in Eclipse, you can accomplish the same using Properties > C/C++ Build > Settings > Tool Settings > GCC C++ Compiler > Directories

    Static/Shared-Object Libraries

    For static/shared-object libraries, you have to specify two options:

    1. -l --> The name of the library, less the 'lib' prefix and the file suffix (e.g., libboost_serialization.dll -> boost_serialization
    2. -L --> The directory to look for the library file in. This is only needed if the library is on a non-standard path.

    As @Chris pointed out, for a managed makefile project, both of these options can be set through Properties > C/C++ Build > Settings > Tool Settings > GCC C++ Linker > Libraries

    0 讨论(0)
  • 2021-01-19 13:06

    Is Properties > C/C++ Build > Settings > Tool settings > ... Linker > Libraries what do you search? It's where you add the -l options when compiling from command line.

    0 讨论(0)
  • 2021-01-19 13:12

    I had the same problem. Changing settings in C/C++ Build --> Settings solved the problem. Ensure that the ".lib" filename extension is excluded! See the screenshot below:

    0 讨论(0)
  • 2021-01-19 13:12

    Solved by adding -I to makefile.

    BOOST =     C:/Users/neo/Documents/boost_1_52
    
    CXXFLAGS =  -O2 -g -Wall -fmessage-length=0 -I$(BOOST)
    
    OBJS =      p1.o
    
    LIBS =      
    
    TARGET =    p1.exe
    
    
    $(TARGET):  $(OBJS)
        $(CXX) -o $(TARGET) $(OBJS) $(LIBS)
    
    all:    $(TARGET)
    
    clean:
        rm -f $(OBJS) $(TARGET)
    
    0 讨论(0)
提交回复
热议问题