Author Topic: C++ static library usage  (Read 10904 times)

hexbase

  • Guest
C++ static library usage
« on: December 20, 2012, 01:52:26 AM »
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:
Code: [Select]
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:
Code: [Select]
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

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: C++ static library usage
« Reply #1 on: December 20, 2012, 02:11:46 AM »
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

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: C++ static library usage
« Reply #2 on: December 20, 2012, 02:17:53 AM »

qWord

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: C++ static library usage
« Reply #3 on: December 20, 2012, 02:26:49 AM »
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

  • Member
  • **
  • Posts: 212
    • LLC "AMS"
Re: C++ static library usage
« Reply #4 on: December 20, 2012, 03:00:37 AM »
Maybe extrn C allowed only in decalration - first, implamentation - second, not suppose usnig this keyword.

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: C++ static library usage
« Reply #5 on: December 20, 2012, 03:27:05 AM »
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

  • Guest
Re: C++ static library usage
« Reply #6 on: December 20, 2012, 03:48:52 AM »
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

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: C++ static library usage
« Reply #7 on: December 20, 2012, 04:11:08 AM »
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

  • Member
  • *****
  • Posts: 1987
Re: C++ static library usage
« Reply #8 on: December 20, 2012, 05:25:54 AM »
Hi hexbase,

Welcome to the forum.

Could you post here your library? ( attachment )

jj2007

  • Member
  • *****
  • Posts: 9635
  • Assembler is fun ;-)
    • MasmBasic
Re: C++ static library usage
« Reply #9 on: December 20, 2012, 05:41:28 AM »
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

  • Member
  • *****
  • Posts: 1987
Re: C++ static library usage
« Reply #10 on: December 20, 2012, 05:48:04 AM »
Hi Jochen,

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

hexbase

  • Guest
Re: C++ static library usage
« Reply #11 on: December 20, 2012, 08:16:22 AM »
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
Code: [Select]
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

  • Member
  • *****
  • Posts: 9635
  • Assembler is fun ;-)
    • MasmBasic
Re: C++ static library usage
« Reply #12 on: December 20, 2012, 08:43:32 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

  • Member
  • ****
  • Posts: 969
  • Neuroscience Fans
Re: C++ static library usage
« Reply #13 on: December 20, 2012, 09:33:40 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

  • Guest
Re: C++ static library usage
« Reply #14 on: December 20, 2012, 10:00:33 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?