importing libraries from elsewhere

This is a discussion on importing libraries from elsewhere within the C++ Programming forums, part of the General Programming Boards category; How would I include a lib that is in a different folder than vc7? e.g. the lib is in C:\abc\Lib. ...

  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 08: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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    ZuK
    ZuK is offline
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21