On Fri, Aug 13, 2010 at 19:18, Matthew Aichi <[email protected]> wrote:
>
> Sorry, I should probably be more specific, the command line I
> mentioned is for my company's library, which I'm trying to link crypto+
> + into. Crypto++ I'm building with the GNUmakefile.
> ( -DNDEBUG -O2 -fvisibility=hidden -fPIC -ffunction-sections -fdata-
> sections -arch x86_64 -arch i386 -DCRYPTOPP_DISABLE_ASM -pipe -c )
>
>
> I took your advice and tried to link my library against the built
> libcryptopp.a (g++ -I../common -I../../apps/support -I../../apps/
> crypto/ -Wall -Wno-uninitialized -fvisibility=hidden -fPIC -m32 -O2 -
> DNDEBUG -shared -dynamiclib $(LIB_DIR)/libmylibrary.dylib ../../apps/
> crypto/libcryptopp.a *.o)
>
I don't think you can include a static library like that with Apple's
linker. I think you need to use
-L/path/to/directory/containing/library -llibname instead.

Here's a quick sample I knocked out on my system:

beelzebot:testlib geoff$ cat testlib.h
#if !defined(__TESTLIB_H__)
#define __TESTLIB_H__

void GenerateAndPrintAKey();

#endif //!defined(__TESTLIB_H__)

beelzebot:testlib geoff$ cat testlib.cc
#include "testlib.h"

#include "cryptlib.h"
#include "DSA.h"
#include "hex.h"
#include "osrng.h"

#include <iostream>
#include <string>
using namespace std;


__attribute__((visibility("default"))) void GenerateAndPrintAKey()
{
        using namespace CryptoPP;
        AutoSeededRandomPool rng;

        DSA::PrivateKey PrivateKey;
        PrivateKey.GenerateRandomWithKeySize(rng, 1024);

        string encodedPrivateKey;

        PrivateKey.Save( HexEncoder(new StringSink(encodedPrivateKey)).Ref() );

        cout << "Private key: " << encodedPrivateKey << endl;
                
}

beelzebot:testlib geoff$ cat sample.cc
#include <iostream>

#include "testlib.h"


using namespace std;


int main(int argc, char**argv)
{
        cout << "Testing testilb.dylib:" << endl;
        GenerateAndPrintAKey();
        cout << "Done." << endl;
        return 0;
}

beelzebot:testlib geoff$ g++ -I
/Users/geoff/3rdparty-sources/cryptopp-560 -Wall -Wno-uninitialized
-fvisibility=hidden -fPIC -m32 -DNDEBUG -shared -dynamiclib -o
libtestlib.dylib testlib.cc
-L/Users/geoff/3rdparty-sources/cryptopp-560 -lcryptopp

beelzebot:testlib geoff$ g++ -m32 -o sample sample.cc -L. -ltestlib

beelzebot:testlib geoff$ otool -L sample
sample: 
        libtestlib.dylib (compatibility version 0.0.0, current version 0.0.0)
        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current 
version 7.9.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 125.2.0)

beelzebot:testlib geoff$ ./sample
Testing testilb.dylib:
Private key: 
3082014B0201003082012C06072A8648CE3804013082011F02818100D72D44B53F3D063B4964A4248FE507DC58194C2C7BB3D417E2CAD12AE9440D68DA04BC905758ECA00838A631BEF90BC9B50C4A935F8635F7FDCD89FDE5A15AB9C7170057C5E08ADB6F6118033D3B25552390085B42BF980275BD8AD7C4143E9F23A406B0CE11A64F62C80D32994AD37DA49AEAC6004383C7A723AB3BBDD0340B02150098BFBA32989D77908B9C8602C53205F5CD42E21B02818100A38BB141FAA7C9052E95CE8DD05523ECCCC245310C4B92B7F6BFBC9446D3BB1E33D10825526E3C23EA1DCDDA01795AD932953210A2FDC8F3B5CC0774FB9B80F07AA6063D903619A8417F0815809058246CD8A6A90C18C054C686E4AF502D34AD819D6DE0BCECF552E97FA802FF6C418C38A15199C7A6A4AF7DA642C2BB767DF904160214320CA63319E7AFC3C4410454466EA15F6CF2A752
Done.


When building my dylib, there were few warnings that I didn't bother
to resolve because they weren't important for the purpose of
demonstrating this; at a quick glance, they resulted from differences
between my default crypto++ build settings and the settings I used on
my sample project.

Hope this helps. I used Snow Leopard with GCC 4.2.1.

Geoff

-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.

Reply via email to