0

Given the following files

RsbbDec.exe

Run_RsbbDec.exe

TRSCompress.dll

TRSCompress.lib

and the following example code:

#include <iostream>

#pragma   comment(lib,   "TRSCompress.lib.") 
extern "C" __declspec(dllexport) int    Run_RsbbDec(const char* Input_File, int vbr_en, int bitrate , char *ErrMsg);
#define TEXTLEN 1024


int main()
{
    char ErrMsg[TEXTLEN];

    if(Run_RsbbDec("audio.pcm", 1, 1, ErrMsg)) 
    {       
        std::cout <<"ok";
    }
    else
    {
        std::cout <<"error";
    }
}

How do I make the sample code work? The only instruction I was given was to make sure that the .dll and the 2 exes are in the same directory.

It seems to me that the main point of the demo code is to run the Run_RsbbDec function which I think is located in one of the executables.

I get a linker error when I run the code:

/tmp/ccuvBnWV.o:main.cpp:(.text+0x2b): undefined reference to `Run_RsbbDec'

I am using this command to compile:

g++ main.c RsbbDec.exe Run_RsbbDec.exe
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
user3702643
  • 1,465
  • 5
  • 21
  • 48
  • What command line are you using to compile? I presume that your (currently unidentified) toolchain needs told to link your C++ with those other binaries. – underscore_d Nov 07 '19 at 11:23
  • Added the command that I used to compile in the question. I've never compiled using other executables before. I've always only used my own .cpp files. So I am not too sure what to do – user3702643 Nov 07 '19 at 11:25
  • 2
    I don't think the dot at the end of `"TRSCompress.lib."` should be there. – interjay Nov 07 '19 at 11:31
  • Your output looks like Linux, but DLLs & EXEs are for Windows. What's going on there? What is your environment? You haven't given many details. – Lightness Races in Orbit Nov 07 '19 at 11:41
  • Im compiling on windows using Cygwin. I can compile using linux if needed – user3702643 Nov 07 '19 at 11:42
  • You _can't_ compile on Linux, because [it won't work](http://coliru.stacked-crooked.com/a/d53b16bc8b2e3086). Please add the detail about Cygwin to the question. That's probably important. – Lightness Races in Orbit Nov 07 '19 at 11:42
  • And what are these files? Where did they come from? Who built them? With what toolchain and in what environment? – Lightness Races in Orbit Nov 07 '19 at 11:50
  • @LightnessRaceswithMonica Unfortunately I do not have information about the files. They were given to me by a friend asking for help so I am working blind here which is what makes it so difficult – user3702643 Nov 07 '19 at 12:03

1 Answers1

1

Likely, the third-party supplied DLL was not built under Cygwin, but natively with Visual Studio (or similar).

That's okay, but you have to do some more work to form a compatibility between the two different environments.

You can read about it on the Cygwin website's page "Building and Using DLLs":

If you have an existing DLL already, you need to build a Cygwin-compatible import library. If you have the source to compile the DLL, see the section called “Building DLLs” for details on having gcc build one for you. If you do not have the source or a supplied working import library, you can get most of the way by creating a .def file with these commands (you might need to do this in bash for the quoting to work correctly):

echo EXPORTS > foo.def
nm foo.dll | grep ' T _' | sed 's/.* T _//' >> foo.def

Note that this will only work if the DLL is not stripped. Otherwise you will get an error message: "No symbols in foo.dll".

Once you have the .def file, you can create an import library from it like this:

dlltool --def foo.def --dllname foo.dll --output-lib foo.a

Alternatively, use native tools to build your own program.

Also, the pragma is wrong; there's an errant period at the end of the filename.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055