0

Recently, I have downloaded the Irrklang sound library to use with my C++ programs. To test it out, I have Installed and linked the library in Code::Block's compiler settings and in my projects build settings. However, whenever I try to build & run the following code:

#include <irrKlang.h>
using namespace std;
using namespace irrklang;
int main(){
    ISoundEngine* engine = createIrrKlangDevice();
}

The "Build Messages" tab throws the following error:

|Line 5|undefined reference to`_imp___ZN8irrklang20createIrrKlangDeviceENS_21E_SOUND_OUTPUT_DRIVEREiPKcS2_'|

And here's the error from the "Build Log" tab:

64bit-1.5.0\lib\Winx64-visualStudio\irrKlang.lib"
obj\Debug\main.o: In function `main':
C:/Users/Johnny/Desktop/Python/Learner/main.cpp:5: undefined reference to _imp___ZN8irrklang20createIrrKlangDeviceENS_21E_SOUND_OUTPUT_DRIVEREiPKcS2_'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

I have to tell you, this is my first time downloading and using a library with C++. I used this tutorial: http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/

I've looked up this error on google, and while people with the same problem come up, all of the solutions they got are either too vague or their error report was caused by a different error.

Here's some pages I looked through:

http://www.ambiera.com/forum.php?t=939

I looked through more than just this one, mostly on the same forum, but I can only post a maximum of two links, and I decided that it was more important that you could tell how I linked the library.

Johnny Sasaki
  • 45
  • 1
  • 1
  • 5
  • Looks like you didn't add the `import library` to your project. The linker is looking for that function you're calling in `main`, but can't find it. The `_imp` prefix indicates that the function (stub) is located in the import library (that you should have received and added to your project). – PaulMcKenzie Jul 25 '15 at 03:01
  • `import library` ? What's that? @PaulMcKenzie – Johnny Sasaki Jul 25 '15 at 03:05
  • Your program is calling a function. Where is that function located? That is what the linker is complaining about -- it can't find it. That function is located in the import library (.LIB) file that should have come with your sound library. You then need to add that file to your project, so that the linker knows where to find that function. And BTW, you need to get familiar with import (and static libraries) if you intend to use third-party DLL's and modules. As a matter of fact, your URL link outlines this: `5) Tell the linker which static or import library files to link.` – PaulMcKenzie Jul 25 '15 at 03:06
  • Okay, so I followed that site's directions more closely now. I have `irrKlang.dll` in my project's directory. I went throught the linker settings and made sure that the `.lib` file is linked. And I'm _still_ getting the same error message. – Johnny Sasaki Jul 25 '15 at 04:00
  • We can't see how you've linked your program or what might be wrong with the linkage unless you post the linker commandline that is failing. It's in the Build log (not the Build messages). It's the `g++` commandline from which the error follows. – Mike Kinghan Jul 25 '15 at 10:57
  • Alright, I've edited my question to show the error in my build log as well as my build messages tab. @MikeKinghan – Johnny Sasaki Jul 25 '15 at 19:52
  • @JohnnySasaki Not asking to see the error again. Asking to see the linker command that failed, reporting that error, so we can see what you had actually told the linker to do when it reported that error. It will be the last commandline beginning with `g++` in the build log before the error. If you're still in doubt, post the whole build log. – Mike Kinghan Jul 26 '15 at 08:00
  • Oh. Okay, here you go. `mingw32-g++.exe -L"..\..\C++ Libraries (Important!)\irrKlang-64bit-1.5.0" -L"C:\Users\Johnny\Desktop\C++ Libraries (Important!)\irrKlang-64bit-1.5.0\lib\Winx64-visualStudio" -o bin\Debug\Learner.exe obj\Debug\main.o "..\..\C++ Libraries (Important!)\irrKlang-64bit-1.5.0\lib\Winx64-visualStudio\irrKlang.lib" "C:\Users\Johnny\Desktop\C++ Libraries (Important!)\irrKlang-64bit-1.5.0\lib\Winx64-visualStudio\irrKlang.lib"` @MikeKinghan – Johnny Sasaki Jul 26 '15 at 14:07

1 Answers1

1

You are attempting to link a C++ DLL (or rather the export LIB of a DLL) that was built with MS Visual Studio C++ in a program you are building with GNU C++.

You can't do that for several reasons, the simplest of which is that the MS and GCC compilers employ different name-mangling conventions for C++ symbols. Thus your compiler mangles irrklang::createIrrKlangDevice as:

ZN8irrklang20createIrrKlangDeviceENS_21E_SOUND_OUTPUT_DRIVEREiPKcS2_

for linkage purposes, but in the export library you are trying to link, it is exported as:

createIrrKlangDevice@irrklang@@YAPEAVISoundEngine@1@W4E_SOUND_OUTPUT_DRIVER@1@HPEBD1@Z

The fact that the irrKlang package you have installed stores this export library in irrKlang-64bit-1.5.0\lib\Winx64-visualStudio is a hint that it is only compatible with the Windows 64-bit Visual Studio toolchain.

To link 64-bit irrKlang.dll with a 64-bit program that you build with the GNU toolchain you would have to obtain the irrKlang source code and rebuild the dll with your GNU toolchain. I don't believe that source code is publicly available. Otherwise you can only build a 64-bit program with Visual Studio.

If you are content to build a 32-bit program (which will run on 64-bit Windows), then you may use the 32-bit version of irrKlang 1.5. It contains 32-bit static and dynamic library builds that were built with 32-bit GCC and reside in subfolders called win32-gcc, as opposed to Winx64-visualStudio.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182