Thread: g++ what does -l do?

  1. #1
    Registered User
    Join Date
    Mar 2015
    Posts
    24

    g++ what does -l do?

    I'm trying to link some libraries with g++ and i'm getting some errors.

    From what I've heard, -l used for specifying library name. But what does that mean? i'm getting an error whenever I put my library name next to -l.

    Code:
    g++ -lSDL2
    and -I specifies the directory for the header files, right?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    How about posting your actual error messages?

    The command line you posted in itself is meaningless without some object files of your compiled code to go with it.
    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.

  3. #3
    Registered User
    Join Date
    Mar 2015
    Posts
    24
    Quote Originally Posted by Salem View Post
    How about posting your actual error messages?

    The command line you posted in itself is meaningless without some object files of your compiled code to go with it.
    I'm trying to compile irrlicht game cpp file.

    Code:
    g++ -std=c++11 main.cpp -o main.exe
    error: undefined reference to 'imp_createDevice'

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Did you try linking with the irrlicht library, and not the SDL library?

    You seem to know all the right components for solving the problem, all you need is the right library name.
    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.

  5. #5
    Guest
    Guest
    Chances are, you also need to tell the compiler where the library is. You do that with the -L (capital L) flag.
    Code:
    -LC:\Path\to\SDL -lSDL2
    ...something along those lines.

Popular pages Recent additions subscribe to a feed