Linking program to a .lib without changing Project Settings (Looking for code)

This is a discussion on Linking program to a .lib without changing Project Settings (Looking for code) within the C++ Programming forums, part of the General Programming Boards category; Hello all. I've tried Googling and searching this forum, but not really sure what to search for. I need to ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    74

    Linking program to a .lib without changing Project Settings (Looking for code)

    Hello all. I've tried Googling and searching this forum, but not really sure what to search for.

    I need to link my project to a specific .lib file, but I don't want to use the Project Settings. Is there a way I can write code for this?

    Ex:
    Code:
    #include "...Blah.h"
    // I want to link to a .lib file here. What code do I need?  I'm pretty sure I've done this before, but I forgot.
    
    int main(){}

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    You need to use compiler settings. (Or project settings or whatever.) -l (lowercase L) plus possibly -L for gcc/g++.
    Code:
    $ g++ codeform.c -L ~/libraries -lform
    links to ~/libraries/libform.a.

    Why don't you want to use project settings? You can distribute the project file with your program.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    74

    Cool

    Quote Originally Posted by dwks
    Why don't you want to use project settings?
    I would like to, but I couldn't get to work what I wanted to.

    I'm using VC++ 2005 Express:

    Code:
    Project settings -> Linker -> Input -> Additional Dependicies = Backend.lib
    Everything works fine as long as I have Backend.lib in my project's directory at compile time, but it is in another directory. I'm still developing my Backend.lib so instead of constantly compiling it then going to it.. copying it over to my other project that will use it I just want to point to it.

    But, the following wouldn't work:
    Code:
    Project Settings -> Linker -> Input -> Additional Dependicies = c:\Documents and Settings\Work\Programming\Backend\Debug\Backend.lib
    It doesn't like me specifying a directory or atleast one with spaces.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    74
    Oh *&#$# I'm so stupid.. It just dawned on me to try adding quotes around it.. Of course it worked.. Man I hate being an idiot.

    Code:
    Project Settings -> Linker -> Input -> Additional Dependicies = "c:\Documents and Settings\Work\Programming\Backend\Debug\Backend.lib"

  5. #5
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    You should also be able to configure which directories it searches for .lib files.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  6. #6
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Microsoft specific extension:

    Code:
    #pragma lib

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking Fortran procedures with C program
    By gest in forum C Programming
    Replies: 5
    Last Post: 07-14-2003, 12:35 PM
  2. Another question on classes
    By hpy_gilmore8 in forum C++ Programming
    Replies: 26
    Last Post: 05-24-2003, 09:11 AM
  3. linking an opengl program
    By raits in forum C++ Programming
    Replies: 11
    Last Post: 03-11-2003, 12:54 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. How do I include a .lib file in my project
    By tudehopet in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2002, 10:01 AM

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