News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

C++ static library usage

Started by hexbase, December 20, 2012, 01:52:26 AM

Previous topic - Next topic

hexbase

Hi,
Im a newbie in asm and in programming in general.
I wanted to use re2win library. I added a new sourcefile in the project and created a function to be called in masm. Something like:
extern "C" bool __stdcall atestfunc (int first, int second){
}

Then I compiled it as static library with no problem.
Then I created a .inc file to use the function in masm and then included the lib.
When building, I get this:
POLINK: fatal error: Corrupt library: '\masm32\lib\re2.lib'; unable to find symb
ol '_atestfunc@8' in member 'Release\test.obj'.


Dumpbin /SYMBOLS doesnt show any symbol in the lib.

Thanks

dedndave

are you trying to use an OBJ as a LIB ?
you can put the OBJ inside a LIB
a LIB is a collection of OBJ's, essentially
i guess 1 is a collection   :P

otherwise, you can directly link the OBJ with the OBJ of the test project


qWord

Hello,
your problem is probably the name mangling of C++ (VC++?) - the this document for more details.

qWord

EDIT: I didn't see you are using extern "C"
MREAL macros - when you need floating point arithmetic while assembling!

Adamanteus

Maybe extrn C allowed only in decalration - first, implamentation - second, not suppose usnig this keyword.

MichaelW

I'm guessing that the problem is that in your cpp source you have declared atestfunc but not defined it.

I don't have VC set up on my system, so I used the VC Toolkit 2003 compiler and batch files.

As a quick check of the symbols in a library, instead of taking the time to use Dumpbin or similar just open the library in a text editor and look at the names.
Well Microsoft, here's another nice mess you've gotten us into.

japheth

There might be several problems:

- your lib was created for 64-bit
- your lib is in Unix AR format ; this format is not quite compatible with the MS AR format.
- your lib might be "empty" - you are "new to programming in general" and may have done something stupid
  (don't worry, lots of people here are doing this virtually all the time  :bgrin: )

The simplest is to zip your lib and post it here - if it isn't too large.


qWord

I've build the lib and was also unable to get it link - maybe because of the project settings there are a lot of dependencies that I wasn't able to fix. However, I was able to build a DLL of it (simple add __declspec(dllexport) to the function / classes you want to export).
MREAL macros - when you need floating point arithmetic while assembling!

Vortex

Hi hexbase,

Welcome to the forum.

Could you post here your library? ( attachment )

jj2007

Erol,

The lib is 23MB (of which 755184 bytes dedicated to "stringprintf.obj" ;))

By the way, to my great surprise, Visual C++ 2010 Express was able to convert it, and even compiled it.

Vortex

Hi Jochen,

Very big library. Sorry, I didn't knew it.

hexbase

Hi guys,

I was able to build it as a dll. I just selected to build it as dll in the project settings.  I added a test function called "matchparcial", like
extern "C" bool __declspec(dllexport) __stdcall matchparcial (string *first, string *second){
}


Dumpbin shows the function as exported. How do I use the dll inside my program?
Attached is the dll and dumpbin info (not all of it).
The dll is small, compared to the lib file. I dont know if that's ok.

Thanks

jj2007

Quote from: hexbase on December 20, 2012, 08:16:22 AM
How do I use the dll inside my program?

From C or assembler?

Here is one option:

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  Dll "\RE2\re2.dll"                        ; load the DLL
  Declare matchparcial, 2        ; matchparcial expects 2 pointers
  Inkey Str$("Result=%i", matchparcial("String1", "String2"))
  Exit
end start

It assembles, links and runs - and then stops complaining that it can't find GetTickCount64 in Kernel32.dll ...

Farabi

Quote from: jj2007 on December 20, 2012, 08:43:32 AM
Quote from: hexbase on December 20, 2012, 08:16:22 AM
How do I use the dll inside my program?

From C or assembler?

Here is one option:

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  Dll "\RE2\re2.dll"                        ; load the DLL
  Declare matchparcial, 2        ; matchparcial expects 2 pointers
  Inkey Str$("Result=%i", matchparcial("String1", "String2"))
  Exit
end start

It assembles, links and runs - and then stops complaining that it can't find GetTickCount64 in Kernel32.dll ...

Whoa your MASM BASIC is great :t
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

hexbase

Quote from: jj2007 on December 20, 2012, 08:43:32 AM
Quote from: hexbase on December 20, 2012, 08:16:22 AM
How do I use the dll inside my program?

From C or assembler?

Here is one option:

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  Dll "\RE2\re2.dll"                        ; load the DLL
  Declare matchparcial, 2        ; matchparcial expects 2 pointers
  Inkey Str$("Result=%i", matchparcial("String1", "String2"))
  Exit
end start

It assembles, links and runs - and then stops complaining that it can't find GetTickCount64 in Kernel32.dll ...

I put re2.dll in the masm32 folder and used: Dll "\masm32\re2.dll". When I run the program, it complains it cannot load the dll (loadlibrary). What im doing wrong?