Author Topic: problems linking libraries [SOLVED]  (Read 4656 times)

Offline sspecter

  • Multiple posting newcomer
  • *
  • Posts: 13
  • I feel like I could... TAKE OVER THE WORLD!!!
problems linking libraries [SOLVED]
« on: February 11, 2006, 04:41:41 am »
Hi all

Im having hard time linking library in my application.

Im making an Ogre application, and must call headers (.h) and libraries (.dll). I am putting the header directory in release/directories/compiler and the libraries directory in release/directories/linker.

My application is finding the headers but not the libraries. I tried to add all libraries in release/linker/link libraries with absolute, relative and no path but it didnt worked

The only thing that works is putting all DLLs in my application's dir (the app runs nicely). But I dont want do that.


 Maybe this is a newbie question but: How can I call/link a library from other directory?
« Last Edit: February 12, 2006, 12:09:09 am by sspecter »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: problems linking libraries
« Reply #1 on: February 11, 2006, 09:54:14 am »
Please describe your problem better.
What you said above gives no clue on what you 've done wrong. It only gives clues that you really did something wrong :)

To link a DLL, you need to link to its import library (libXYZ.a for gcc, XYZ.lib for msvc). Put the path with your libraries in "Project->Build options->Directories->Linker" and the libraries (without any path info) in "Project->Build options->Linker->Libraries".

If you still can't make it work, post here the full build log. To enable it, go to global compiler options "Other" page and set logging to full for the compiler you 're using. Then rebuild your project, copy the build log and paste it here...
Be patient!
This bug will be fixed soon...

Offline yop

  • Regular
  • ***
  • Posts: 387
Re: problems linking libraries
« Reply #2 on: February 11, 2006, 10:31:07 am »
To link a DLL, you need to link to its import library (libXYZ.a for gcc, XYZ.lib for msvc).
Or use the -rpath (see the man page) flag for gcc linker (don't know the equivelant for the m$ linker)
Life would be so much easier if we could just look at the source code.

Offline sspecter

  • Multiple posting newcomer
  • *
  • Posts: 13
  • I feel like I could... TAKE OVER THE WORLD!!!
Re: problems linking libraries
« Reply #3 on: February 11, 2006, 06:27:08 pm »
Sorry, my english is not that good, so ill try to be clearer.

this is what im doing:

- I put all .H files i need in \include directory
- I put all .DLLs and .A i need in \lib directory
- I add the "include" directory in Project->Build options->Release->Directories->Compiler
- I add the "lib" directory in Project->Build options->Release->Directories->Linker
- I tried everything at Project->Build options->Release->Linker->Link_Libraries. i've added all .A files, or all .DLL files, with or without patches. Dont matter what I do, I aways get the same result

What I get:

- The project is compiling, but windows give "Cannot find ogremain.dll" error window then executing. ogremain is one of the DLLs im trying to link.
- The project run without any error if I place all DLLs in the project root directory (same as the project source)

Obviously codeblocks isnt finding the DLLs. I dont have any clue why this is happening.

If you still can't make it work, post here the full build log. To enable it, go to global compiler options "Other" page and set logging to full for the compiler you 're using. Then rebuild your project, copy the build log and paste it here...

I enabled the log, but cant find it. were it is logged? I cant see the log anywere :(

Is there any Codeblock documentation, oficial or not? Ive searched through wiki but it didnt helped me much.

How i can use this -rpath?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: problems linking libraries
« Reply #4 on: February 11, 2006, 06:53:50 pm »
Quote
- I put all .DLLs and .A i need in \lib directory

So your problem is not with linking, but that it can't find the DLLs at runtime.

The DLL must be located either at the same directory with your EXE (preferred way), or in a system-wide path like \windows\system32 (not advised).
Be patient!
This bug will be fixed soon...

Offline yop

  • Regular
  • ***
  • Posts: 387
Re: problems linking libraries
« Reply #5 on: February 11, 2006, 07:48:46 pm »
How i can use this -rpath?
In your case (now that it's clear) you don't need it. Mandrav's advice is what you need.
Life would be so much easier if we could just look at the source code.

Offline sspecter

  • Multiple posting newcomer
  • *
  • Posts: 13
  • I feel like I could... TAKE OVER THE WORLD!!!
Re: problems linking libraries
« Reply #6 on: February 11, 2006, 09:16:30 pm »
Thanks for the help

Then... Is there a way to add system paths in codeblocks? So that when my program runs the path is added?

If dont, there is any way to load libraries in another directory (without adding system paths)?


Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: problems linking libraries
« Reply #7 on: February 11, 2006, 10:01:55 pm »
... Is there a way to add system paths in codeblocks? ...

actually no :-(

but i had a similar need and "solved" it by the following workaround :
create a cmd-script and set your needed path(es) there to your PATH environment variable,

i use scripts something like the following

Code: [Select]
@if "%ENVMYXYZAPP%" == "" (
    set ENVMYXYZAPP=SET
    echo Setting my environment for xyz app ...
    set PATH=D:\my\path\for\xyz\app;%PATH%
    start D:\programme\codeblocks\codeblocks.exe d:\devel\xyz\xyz.cbp
)

which works with Windows XP well,

you can look at the attached project, which i used in former times
for testing the debugger, but it uses two dll's in separate subdirectories,

there is one start_cb_???.cmd to start the ide with the workspace,
and one start_???.cmd to test the executable without ide.

look at that files and you'll get the idea

[attachment deleted by admin]
« Last Edit: February 11, 2006, 10:04:26 pm by tiwag »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: problems linking libraries
« Reply #8 on: February 11, 2006, 10:04:55 pm »
Even if there was a way, your app would run fine inside C::B but would fail to run outside of C::B (on its own)...
I suggest you re-think your project's (folder) layout...
Be patient!
This bug will be fixed soon...