Author Topic: ERROR: ld: cannot find -lbgi  (Read 12773 times)

Offline jack71

  • Single posting newcomer
  • *
  • Posts: 1
ERROR: ld: cannot find -lbgi
« on: May 02, 2014, 04:57:55 pm »
Building a c++ grahphics program and get link error:  cannot find -lbgi
It IS there and I've checked everything related to Libraries and Other Linker options:

I know the rules say no linker errors here, but first I want to rule out any Libraries and Other Linker options errors.  I believe the BUILD LOG below indicates that Libraries and Linker options are correct AND complete. If someone can confirm I will move on to GCC forums.

HERE IS THE BUILD LOG (which results in ld: cannot find -lbgi)
mingw32-g++.exe   -I"C:\Program Files\CodeBlocks-EP\sdk\winbgim\include" -I"C:\Program Files\CodeBlocks-EP\sdk\winbgim\lib"  -c "C:\C-C++ Development\analog_clock.cpp" -o "C:\C-C++ Development\analog_clock.o"

mingw32-g++.exe  -o "C:\C-C++ Development\analog_clock.exe" "C:\C-C++ Development\analog_clock.o"  -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32  "C:\Program Files\CodeBlocks-EP\sdk\winbgim\lib\libbgi.a"

When I look at: C:\Program Files\CodeBlocks-EP\sdk\winbgim\lib, I see "libbgi.a", so it is there.
When I paste "file:///C:/Program%20Files/CodeBlocks-EP/sdk/winbgim/lib/" into my browser URL pane, it shows "libbgi.a" (proving it is there).

Linker settings:
  Created new project with WinBGIm template, graphics only
  Libraries: C:\Program Files\CodeBlocks-EP\sdk\winbgim\lib\libbgi.a
  Other Linker options: -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32


Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: ERROR: ld: cannot find -lbgi
« Reply #1 on: May 02, 2014, 05:02:53 pm »
Which WinBGIm template ?
Code::Blocks-EP is not maintained by us (the Code::Blocks devs), neither is the WinBGIm template.

I suggest asking on the site you got Code::Blocks-EP from, they might know better what's going wrong.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2567
Re: ERROR: ld: cannot find -lbgi
« Reply #2 on: May 02, 2014, 09:21:08 pm »
if you post a build log, please use code tags (the # symbol in the new post editor)

I think you made a error by setting the paths/ libs...
in the build log there are many paths with no option in the front:
Code: [Select]
ingw32-g++.exe  -o "C:\C-C++ Development\analog_clock.exe" "C:\C-C++ Development\analog_clock.o"  -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32  "C:\Program Files\CodeBlocks-EP\sdk\winbgim\lib\libbgi.a"
here the last lib is wrong. It should be
Code: [Select]
-l"C:\Program Files\CodeBlocks-EP\sdk\winbgim\lib\libbgi.a"or
Code: [Select]
-L"C:\Program Files\CodeBlocks-EP\sdk\winbgim\lib\"
how to set up this things you can read in the wiki: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F

greetings

Offline Vuki

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: ERROR: ld: cannot find -lbgi
« Reply #3 on: May 03, 2014, 11:40:54 am »
mingw32-g++.exe  -o "C:\C-C++ Development\analog_clock.exe" "C:\C-C++ Development\analog_clock.o"  -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32  "C:\Program Files\CodeBlocks-EP\sdk\winbgim\lib\libbgi.a"

Linker settings:
  Created new project with WinBGIm template, graphics only
  Libraries: C:\Program Files\CodeBlocks-EP\sdk\winbgim\lib\libbgi.a
  Other Linker options: -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

Your problem is that you try to link with libbgi.a twice. It's valid and sometimes it's necessary, but the way you do it causes the error.

You already provided a full path to libbgi.a in "Libraries". This should be enough.
But in "Other Linker options", you try to link it again, this time with "-lbgi". Using -l implies that the library is either in compiler search path or in a directory that you added to "Linker Search Directories" window. Since libbgi.a is not there, the compiler reports error.

The solution is easy: remove "-lbgi" from "Other Linker options" OR add "C:\Program Files\CodeBlocks-EP\sdk\winbgim\lib\" to linker search directories (note: you should avoid paths with spaces such as "Program Files").

And it's better to provide library names in "Libraries" section (gdi32, comdlg32, uuid, oleaut32, ole32) than in "Other Linker options" because it's easier and you may hit the issue of libraries order when linking (as you see, "Other Linker options" have a priority.