How to include a third party library

109 views
Skip to first unread message

Hongli Yin

unread,
Jul 21, 2015, 1:17:33 PM7/21/15
to mongo...@googlegroups.com
I am building a storage engine and I would like to include a third party library. I've already put libcityhash.a in /usr/local/lib/. But the compiler gives me this error: 

/home/hongli.yin/work/dev/mongo/src/mongo/db/modules/hsdb/src/db.cpp:168: undefined reference to `CityHash64(char const*, unsigned long)'

collect2: error: ld returned 1 exit status

scons: *** [build/opt/mongo/mongod] Error 1


Here is my SConscript file:


  1 Import("env")                                                                                       

  2                                                                                                     

  3 env.Library(                                                                                        

  4     target= 'storage_hsdb_lib',                                                                     

  5     source= [                                                                                       

  6         'src/db.cpp',                                                                               

  7         'src/block_manager.cpp',                                                                    

  8         ],                                                                                          

  9     LIBDEPS= ['/usr/local/lib/cityhash']                                                            

 10     )                                                                                               

 11                                                                                                     

 12 env.Library(                                                                                        

 13     target= 'storage_hsdb_base',                                                                    

 14     source= [                                                                                       

 15         'hsdb_engine.cpp',                                                                          

 16         'hsdb_record_store.cpp',                                                                    

 17         'hsdb_recovery_unit.cpp',                                                                   

 18         'hsdb_index.cpp',                                                                           

 19         'hsdb_global_options.cpp',                                                                  

 20         ],                                                                                          

 21     LIBDEPS= [                                                                                      

 22         'storage_hsdb_lib',                                                                         

 23         '$BUILD_DIR/mongo/bson/bson',                                                               

 24         '$BUILD_DIR/mongo/db/namespace_string',                                                     

 25         '$BUILD_DIR/mongo/db/catalog/collection_options',                                           

 26         '$BUILD_DIR/mongo/db/concurrency/write_conflict_exception',                                 

 27         '$BUILD_DIR/mongo/db/index/index_descriptor',                                               

 28         '$BUILD_DIR/mongo/db/storage/bson_collection_catalog_entry',                                

 29         '$BUILD_DIR/mongo/db/storage/index_entry_comparison',                                       

 30         '$BUILD_DIR/mongo/db/storage/key_string',                                                   

 31         '$BUILD_DIR/mongo/db/storage/oplog_hack',                                                   

 32         '$BUILD_DIR/mongo/util/foundation',                                                         

 33         '$BUILD_DIR/mongo/util/processinfo',                                                        

 34         '$BUILD_DIR/third_party/shim_snappy',                                                       

 35         ]                                                                                           

 36     )                                                                                               

 37                                                                                                     

 38 env.Library(                                                                                        

 39     target= 'storage_hsdb',                                                                         

 40     source= [                                                                                       

 41         'hsdb_init.cpp',                                                                            

 42         'hsdb_options_init.cpp',                                                                    

 43         'hsdb_parameters.cpp',                                                                      

 44         'hsdb_record_store_mongod.cpp',                                                             

 45         'hsdb_server_status.cpp',                                                                   

 46         ],                                                                                          

 47     LIBDEPS= [                                                                                      

 48         'storage_hsdb_base',                                                                        

 49         '$BUILD_DIR/mongo/db/storage/kv/kv_engine',                                                 

 50         ],                                                                                          

 51     LIBDEPS_DEPENDENTS=['$BUILD_DIR/mongo/db/${LIBPREFIX}serveronly${LIBSUFFIX}']                   

 52     )                                                                                               

 53                                                                                                     

 54 env.Library(                                                                                        

 55     target= 'storage_hsdb_mock',                                                                    

 56     source= [                                                                                       

 57         'hsdb_record_store_mock.cpp',                                                               

 58         ],                                                                                          

 59     LIBDEPS= [                                                                                      

 60         'storage_hsdb_base',                                                                        

 61         ]                                                                                           

 62     )

 63                                                                                                     

 64 #env.CppUnitTest(                                                                                   

 65 #   target='storage_rocks_index_test',                                                              

 66 #   source=['src/rocks_index_test.cpp'                                                              

 67 #           ],                                                                                      

 68 #   LIBDEPS=[                                                                                       

 69 #        'storage_rocks_mock',                                                                      

 70 #        '$BUILD_DIR/mongo/db/storage/sorted_data_interface_test_harness'                           

 71 #        ]                                                                                          

 72 #   )                                                                                               

 73                                                                                                     

 74 #env.CppUnitTest(                                                                                   

 75 #   target='storage_hsdb_record_store_test',                                                        

 76 #   source=['hsdb_record_store_test.cpp'                                                            

 77 #           ],                                                                                      

 78 #   LIBDEPS=[                                                                                       

 79 #        'storage_hsdb_mock',                                                                       

 80 #        '$BUILD_DIR/mongo/db/storage/record_store_test_harness'                                    

 81 #        ]                                                                                          

 82 #                                                                                                   

 83                                                                                                     

 84 env.CppUnitTest(                                                                                    

 85    target='storage_hsdb_engine_test',                                                               

 86    source=['hsdb_engine_test.cpp'                                                                   

 87            ],                                                                                       

 88    LIBDEPS=[                                                                                        

 89         'storage_hsdb_mock',                                                                        

 90         '$BUILD_DIR/mongo/db/storage/kv/kv_engine_test_harness',                                    

 91         ]                                                                                           

 92    )

Andrew Morrow

unread,
Jul 22, 2015, 3:32:56 PM7/22/15
to mongo...@googlegroups.com

Hi -

Please see my comment below

On Tue, Jul 21, 2015 at 1:17 PM, Hongli Yin <coolh...@gmail.com> wrote:
I am building a storage engine and I would like to include a third party library. I've already put libcityhash.a in /usr/local/lib/. But the compiler gives me this error: 

/home/hongli.yin/work/dev/mongo/src/mongo/db/modules/hsdb/src/db.cpp:168: undefined reference to `CityHash64(char const*, unsigned long)'

collect2: error: ld returned 1 exit status

scons: *** [build/opt/mongo/mongod] Error 1


Here is my SConscript file:


  1 Import("env")                                                                                       

  2                                                                                                     

  3 env.Library(                                                                                        

  4     target= 'storage_hsdb_lib',                                                                     

  5     source= [                                                                                       

  6         'src/db.cpp',                                                                               

  7         'src/block_manager.cpp',                                                                    

  8         ],                                                                                          

  9     LIBDEPS= ['/usr/local/lib/cityhash']


If cityhash is a library not defined by the mongodb build system, which it is not in this case, then it should be referenced via SYSLIBDEPS, not LIBDEPS. Additionally, you should not set the path here. So, change this to

SYSLIBDEPS=['cityhash']

Thanks,
Andrew
 

Hongli Yin

unread,
Jul 23, 2015, 3:15:37 AM7/23/15
to mongodb-dev, andrew...@mongodb.com
Awesome it works great!

Thank you very much,
Hongli

Hongli Yin

unread,
Jul 23, 2015, 5:51:46 PM7/23/15
to mongodb-dev, andrew...@mongodb.com
Hi Andrew,

I'm having a dumb question, but I cannot find the answer from the documentation. What is the difference between "ns" and "ident" in KVEngine::getRecordStore arguments? I went over some of the test files but these two parameters are always the same.

Thanks,


On Wednesday, July 22, 2015 at 12:32:56 PM UTC-7, acm wrote:

Andrew Morrow

unread,
Jul 23, 2015, 6:58:42 PM7/23/15
to Hongli Yin, mongodb-dev

Hi -

I'd recommend starting a new thread for this question. I don't happen to know the answer, since I'm not an expert on the storage engine API. A new thread is more likely to get attention from the engineers who will know the answer.

Thanks,
Andrew

Reply all
Reply to author
Forward
0 new messages