Thread: importing libraries from elsewhere

  1. #1
    Registered User
    Join Date
    Nov 2005
    Location
    Canada
    Posts
    80

    importing libraries from elsewhere

    How would I include a lib that is in a different folder than vc7? e.g. the lib is in C:\abc\Lib. Is it possible to set something like a PATH value in C++ to allow it to look for libraries in specific places? What is the standard practice?

    Thanks.

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    in which case, use something along the lines of
    Code:
    #include "C:\\abc\\Lib\\my_header.h"
    Note the double-backslashes. Backslash is a special character in C++ string literals for using 'escape sequences' - The double backslash is the escape sequence for the backslash itself

    If you don't like that, you can usually use forward-slash instead:
    Code:
    #include "C:/abc/Lib/my_header.h"

    Edit - if your header files are in a sub-folder of the current project, then you don't need to specify the full path, just the subfolder and filename
    Last edited by Bench82; 01-04-2007 at 09:10 PM.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Location
    Canada
    Posts
    80
    would it make a difference if the path to the library is set in the user environment variables (win xp)?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    In the project settings you can add
    Project Properties/Configuration Properties/C++/General/Additional Include directories

    The new path where the h-files will be looked for

    Or You can open
    Tools/Options/Projects adn Solutions/VC++ Directories

    And add some directories to the Include files list

    This will affect all projects
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You should never use absolute paths inside include statements. It makes it much harder to port the code to even another directory on the same machine, nevermind elsewhere.

    Use Vart's suggestion of setting search paths in the IDE
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Bench82
    in which case, use something along the lines of
    Code:
    #include "C:\\abc\\Lib\\my_header.h"
    The escapes are not processed in preprocessor directives.
    it should be
    Code:
    #include "C:\abc\Lib\my_header.h"
    But still forward slashes are a lot better. Best solution is definately vart's way to add a -I compiler switch
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GCC: Compiling with both static and shared libraries
    By eatwithaspork in forum C Programming
    Replies: 4
    Last Post: 06-23-2008, 01:48 PM
  2. MATLAB importing C libraries
    By chico1st in forum C Programming
    Replies: 1
    Last Post: 05-29-2008, 02:01 PM
  3. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  4. Libraries and headers
    By darksaidin in forum C++ Programming
    Replies: 10
    Last Post: 07-23-2003, 06:24 AM
  5. Importing Libraries
    By Lynchie in forum C Programming
    Replies: 0
    Last Post: 07-19-2002, 02:21 AM