Question

I am trying to use ASIO (Audio Stream Input/Output). I downloaded SDK, but because this SDK has no library, only headers and source files, I had to compile it into a library. Moreover, it was written so that it uses some of the features from MSVC (specifically some macro definitions - _WIN64 and WINVER). I cannot use MSVC for licensing reasons. So I am using Eclipse CDT with MinGW, told preprocessor to set these macros (for Windows 7 x64) and happily compiled a library.

Now when I want to use that library, I keep getting Undefined reference. Can you please tell me what I am getting wrong?

Hello world file (load ASIO driver and print its info):

#include <stdio.h>
#include <stdlib.h>
#include <asio.h>

int main(int argc, char **argv) {
    ASIODriverInfo driverInfo;
    ASIOInit(&driverInfo);

    printf("ASIO version: %ld\n", driverInfo.asioVersion);
    printf("Driver name: %s\n", driverInfo.name);
    printf("Driver version: %ld\n", driverInfo.driverVersion);
    printf("Error message: %s\n", driverInfo.errorMessage);

    return (EXIT_SUCCESS);
}

Verbose output from gcc:

> gcc -v -Lc:/ASIOSDK2/lib/Win7/libasio.a -o ASIOHello.exe src\main.o
> Using built-in specs. COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/lto-wrapper.exe Target: mingw32 Configured with: ../gcc-4.6.1/configure
> --enable-languages=c,c++,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw Thread model: win32 gcc version 4.6.1 (GCC) 
> COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/
> LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.6.1/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../;/mingw/lib/
> COLLECT_GCC_OPTIONS='-v' '-Lc:/ASIOSDK2/lib/Win7/libasio.a' '-o'
> 'ASIOHello.exe' '-mtune=i386' '-march=i386' 
> c:/mingw/bin/../libexec/gcc/mingw32/4.6.1/collect2.exe -Bdynamic -o
> ASIOHello.exe c:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../crt2.o
> c:/mingw/bin/../lib/gcc/mingw32/4.6.1/crtbegin.o
> -Lc:/ASIOSDK2/lib/Win7/libasio.a -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.1 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.1/../../.. -L/mingw/lib src\main.o -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt
> -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.6.1/crtend.o src\main.o: In function
> `main': <my workspace path>\ASIOHello\Debug/../src/main.c:7: undefined
> reference to `ASIOInit' collect2: ld returned 1 exit status Build
> error occurred, build is stopped Time consumed: 454  ms.

And output from nm for the library (only the relevant object):

> asio.o:
> 00000000 b .bss
> 00000000 d .data
> 00000000 N .debug_abbrev
> 00000000 N .debug_aranges
> 00000000 N .debug_info
> 00000000 N .debug_line
> 00000000 N .debug_loc
> 00000000 N .debug_str
> 00000000 r .eh_frame
> 00000000 r .rdata
> 00000000 t .text
> 0000055a T __Z10ASIOFuturelPv
> 0000018c T __Z15ASIOGetChannelsPlS_
> 00000596 T __Z15ASIOOutputReadyv
> 0000052c T __Z16ASIOControlPanelv
> 000001db T __Z16ASIOGetLatenciesPlS_
> 0000029b T __Z17ASIOCanSampleRated
> 0000047b T __Z17ASIOCreateBuffersP14ASIOBufferInfollP13ASIOCallbacks
> 0000022a T __Z17ASIOGetBufferSizePlS_S_S_
> 000002e9 T __Z17ASIOGetSampleRatePd
> 0000031e T __Z17ASIOSetSampleRated
> 000004fe T __Z18ASIODisposeBuffersv
> 00000422 T __Z18ASIOGetChannelInfoP15ASIOChannelInfo
> 000003b1 T __Z18ASIOSetClockSourcel
> 0000036c T __Z19ASIOGetClockSourcesP15ASIOClockSourcePl
> 000003e6 T __Z21ASIOGetSamplePositionP11ASIOSamplesP13ASIOTimeStamp
> 00000103 T __Z8ASIOExitv
> 00000000 T __Z8ASIOInitP14ASIODriverInfo
> 0000015e T __Z8ASIOStopv
> 00000130 T __Z9ASIOStartv
>          U __ZN11AsioDrivers19removeCurrentDriverEv
>          U _asioDrivers
> 00000000 B _theAsioDriver
> 

EDIT:

Okay, now I managed to compile the library so it is accesible by C code (I added

extern "C"

in front of every function declaration. Now the nm output looks like this:

> 0000036c T _ASIOGetClockSources
> 000001db T _ASIOGetLatencies
> 000003e6 T _ASIOGetSamplePosition
> 000002e9 T _ASIOGetSampleRate
> 00000000 T _ASIOInit
> 00000596 T _ASIOOutputReady
> 000003b1 T _ASIOSetClockSource
> 0000031e T _ASIOSetSampleRate
> 00000130 T _ASIOStart
> 0000015e T _ASIOStop

which is looking pretty good. I still have some name mangling tho, it still complains about undefined references.

gcc -v -Lc:/ASIOSDK2/lib/Win7 -lasio -o ASIOHello.exe src\main.o

What am I still missing here?

EDIT 2: I finally made things work. It seems the error was caused by some leftover settings caching. Deleting the project and setting everything up again solved the problem. But thanks @John Zwick for the tip with library compilation, I would be stuck on that for a long time.

Was it helpful?

Solution

I finally made things work. It seems the error was caused by some leftover settings caching. Deleting the project and setting everything up again solved the problem. But thanks @John Zwick for the tip with library compilation, I would be stuck on that for a long time.

OTHER TIPS

ASIO is a C library. The nm output you posted suggests that you compiled it as C++ code. See how the names are mangled? That looks like what you'd expect if you compiled C code as C++. Perhaps you accidentally compiled the ASIO code as C++? If you're not sure, post the transcript of building the library for us.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top