Thread: g++ why is -L not working?

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

    g++ why is -L not working?

    Whenever I put my dll files in the same directory as my main.cpp and use this code,
    Code:
    g++ main.cpp -L. -lMyDll
    it works.

    but if my dll files are in the other directory,
    Code:
    g++ main.cpp -L/myDlls -lMyDll
    it won't work. Why is this not working?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Most paths in linux are in relation to the cwd:
    -L./myDlls

  3. #3
    Registered User
    Join Date
    Mar 2015
    Posts
    24
    I tried that but still it doesn't work. Also, I'm using windows8 and this my error message.

    Code:
    c:/mingw/bin/..lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed operation

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,768
    Show us the command line you used.

    Also try (on a program which does link successfully) a command like this
    g++ -v prog.cpp

    This will make the compile driver print out all sorts of detailed information about the various compilation steps, including for example the exact syntax for -L paths on your system.
    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
    Registered User
    Join Date
    Mar 2015
    Posts
    24
    Quote Originally Posted by Salem View Post
    Show us the command line you used.

    Also try (on a program which does link successfully) a command like this
    g++ -v prog.cpp

    This will make the compile driver print out all sorts of detailed information about the various compilation steps, including for example the exact syntax for -L paths on your system.

    Code:
    g++ -std=c++11 main.cpp -o main.exe -L/lib -lSDL2 -SDL2main
    ^this one gives me an error that says it cannot find SDL2 and SDL2main.


    Code:
    g++ -std=c++11 main.cpp -o main.exe -L. -lSDL2 -lSDL2main
    ^this one works if I move my SDL2 and SDL2main files into a directory where my main.cpp is.


    Also, I get an warning message, "Warning: corrupt .drectve at the end of def file"

    but I think this is related to SDL.


    And for the -v, there were too many messages so I couldn't read them all.
    Last edited by yj1214; 04-03-2015 at 12:16 AM.

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    And for the -v, there were too many messages so I couldn't read them all.
    Great.

    g++ -v prog.cpp > linking_info.txt

    Then attach linking_info.txt to your next post instead of making excuses and denying information.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,768
    > g++ -std=c++11 main.cpp -o main.exe -L/lib -lSDL2 -SDL2main
    > ^this one gives me an error that says it cannot find SDL2 and SDL2main.
    What part of post #2 escaped your attention?

    /lib is an ABSOLUTE path.
    One that cannot exist on winblows since everything needs to be d:/foobar or something.

    Find the absolute path to the directory, then use 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. do-While not working
    By kingsu in forum C Programming
    Replies: 2
    Last Post: 08-01-2009, 01:14 PM
  2. Replies: 9
    Last Post: 03-30-2009, 04:09 AM
  3. Why isn't this working?
    By csisz3r in forum C Programming
    Replies: 5
    Last Post: 09-28-2005, 07:07 PM
  4. I have tried a lot...but this is not working.
    By nomi in forum C Programming
    Replies: 19
    Last Post: 01-13-2004, 12:31 PM
  5. working out
    By ZakkWylde969 in forum A Brief History of Cprogramming.com
    Replies: 35
    Last Post: 11-29-2003, 01:17 PM