This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Building the examples in pc-ble-driver from scratch

I have just received a set of nRF52840 dongles and I want to write applications that run on the PC using the dongle so I have downlaoded the pre-compiled pc-ble-driver located here: https://github.com/NordicSemiconductor/pc-ble-driver/releases/tag/v4.1.1.

I downloaded the zip for the 64-bit version of windows. I assumed that this download would have the connectivity HEX file for the dongle, the libraries I would need to access the dongle's BLE methods, and the h-files. Then I could start a VS 2019 project, link the libraries and the h-files to the project and start writing source code. TO make life easier I get the example heart rate monitor from the pc-ble-driver project on github. It is only one file main.c

Using nRF Connect Desktop tool, I have installed the connectivity_4.1.1_usb_with_s140_6.1.1.hex file onto the dongle. That appears to be the latest version. Everything appears to be fine so far.

I was hoping that the h-files in the directory nrf-ble-driver-4.1.1-win_x86_64\include\sd_api_v6 of the pre-built project would be sufficient; but apparently not. There were several definitions that were not understood. Turns out I have to define the preprocessor variable to set the version as follows #define NRF_SD_BLE_API 6. That solved all those problems. Now the code is ready to build.

I have set the project to use static linking to the libraries assuming that this huge library file nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib would then have all I need. But build the project I get 16 undefined symbols. 

1>main.c
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_ble_gap_adv_set_configure referenced in function advertisement_data_set
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_ble_gap_adv_start referenced in function advertising_start
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_ble_gatts_service_add referenced in function services_init
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_ble_gatts_characteristic_add referenced in function characteristic_init
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_ble_gatts_hvx referenced in function heart_rate_measurement_send
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_ble_gatts_sys_attr_set referenced in function ble_evt_dispatch
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_ble_gatts_exchange_mtu_reply referenced in function ble_evt_dispatch
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_ble_enable referenced in function ble_stack_init
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_ble_cfg_set referenced in function ble_cfg_set
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_rpc_physical_layer_create_uart referenced in function adapter_init
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_rpc_data_link_layer_create_bt_three_wire referenced in function adapter_init
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_rpc_transport_layer_create referenced in function adapter_init
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_rpc_adapter_create referenced in function adapter_init
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_rpc_open referenced in function main
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_rpc_close referenced in function main
1>main.obj : error LNK2019: unresolved external symbol __imp_sd_rpc_log_handler_severity_filter_set referenced in function main
1>E:\projects\BleTester\BleHeartRateMonitor\x64\Debug\BleHeartRateMonitor.exe : fatal error LNK1120: 16 unresolved externals

Do I need another library or is this just saying that somehow I have not set up my Visual Studio project properties to find this library (though I can't see any error in the latter). So I guess I am asking is the nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib the only library I need or am I missing a library or is the library incompatible with Visual Studio?

Parents
  • Hi,

    There were several definitions that were not understood. Turns out I have to define the preprocessor variable to set the version as follows #define NRF_SD_BLE_API 6.

    You also need to add PC_BLE_DRIVER_STATIC and _CRT_SECURE_NO_WARNINGS

     

  • Interesting. Visual Studio already has a parameter setting to indicate whether one is using static or dynamic libraries.

    In any case, adding those two reduces the number of undefined symbols from 16 to 9. There must be more preprocessors or libraries missing.

    1>nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib(sd_rpc_impl.cpp.obj) : error LNK2019: unresolved external symbol __imp_strncpy referenced in function sd_rpc_serial_port_enum
    1>nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib(serial_port_enum.cpp.obj) : error LNK2019: unresolved external symbol __imp_strstr referenced in function "class std::list<struct SerialPortDesc,class std::allocator<struct SerialPortDesc> > __cdecl EnumSerialPorts(void)" (?EnumSerialPorts@@YA?AV?$list@USerialPortDesc@@V?$allocator@USerialPortDesc@@@std@@@std@@XZ)
    1>nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib(serial_port_enum.cpp.obj) : error LNK2019: unresolved external symbol __imp_strtok_s referenced in function "class std::list<struct SerialPortDesc,class std::allocator<struct SerialPortDesc> > __cdecl EnumSerialPorts(void)" (?EnumSerialPorts@@YA?AV?$list@USerialPortDesc@@V?$allocator@USerialPortDesc@@@std@@@std@@XZ)
    1>nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib(serial_port_enum.cpp.obj) : error LNK2019: unresolved external symbol __imp__stricmp referenced in function "class std::list<struct SerialPortDesc,class std::allocator<struct SerialPortDesc> > __cdecl EnumSerialPorts(void)" (?EnumSerialPorts@@YA?AV?$list@USerialPortDesc@@V?$allocator@USerialPortDesc@@@std@@@std@@XZ)
    1>nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib(disphelper.c.obj) : error LNK2019: unresolved external symbol __imp__gmtime64 referenced in function ConvertTimeTToVariantTime
    1>nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib(disphelper.c.obj) : error LNK2019: unresolved external symbol __imp__localtime64 referenced in function ConvertTimeTToVariantTime
    1>nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib(disphelper.c.obj) : error LNK2019: unresolved external symbol __imp__mktime64 referenced in function ConvertTimeTToVariantTime
    1>nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib(jlinkid_reg_lookup.cpp.obj) : error LNK2019: unresolved external symbol __imp_memchr referenced in function "char const * __cdecl std::_Find_unchecked1<char const *,unsigned char>(char const *,char const *,unsigned char const &,struct std::integral_constant<bool,1>)" (??$_Find_unchecked1@PEBDE@std@@YAPEBDPEBD0AEBEU?$integral_constant@_N$00@0@@Z)
    1>nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib(jlinkid_reg_lookup.cpp.obj) : error LNK2019: unresolved external symbol __imp_realloc referenced in function "public: void __cdecl std::_Buf<char>::_Insert<char const *>(char const *,char const *)" (??$_Insert@PEBD@?$_Buf@D@std@@QEAAXPEBD0@Z)
     

  • So far that is what I have done. Except I did not start with the Console project; I started with an empty project but all my properties are filled in as above. I used the properties pages to point to the library but did not add it to the source files. Did that; made no difference. Same 10 LNK2019 errors. Out of desperation I will blow away everything, start from scratch from a console app instead of an empty project and see if that works. (I also have _WIN32 which I think it should be given what's in the source code.)

    It makes no sense, There must be some other piece of configuration information that I have not gotten. I have the configuration set to x64 and not x86 (I think I tried that out of desperation too). Is that a potential issue?

    I blew away everything and started with a console app instead of an empty project. That worked. I cannot tell the difference but in the console app I did not use the property pages to point to the static library. I added it to the source file filter (did that in the empty project too but it did not help). The only difference between the two is the linking of the libraries. In the empty project I set the build to use static debug and set the linker to point to the libraries (this is what I have always done in Visual Studio). Any idea why that does not work? I might want to make this a Win32 GUI application and now I am afraid as how to link needed libraries. Is it something special about the nordic library that CANT be linked via the properties pages?

    I verified the answer (though I don't know why I cant sue the property pages). But in doing so the issue got closed. So I had to reject the answer. That I will change if someone can give any insight into why the library has to be linked this way ...

  • Hi, I followed Sigurd's instruction with Console app, but I get lots of errors which are very similar to  had before (e.g. unresolved external symbol _sd_ble_gap_conn_param_update referenced...). I did add .lib to Source Files instead of linker settings. Is there any instruction missing? I can see nrf-ble-driver-sd_api_v6-mt-4_1_1.dll, do I need to do anything about this? I am using VisualStudio 2019.

  • Hopefully whats in your library 'lib' is the static lib, not the dynamic. The error indictes VS is not finding your static library. If helpful, I can zip up my entire VS project/sln for you. I have started the attempt to make it secure (force pairing) which does not work yet. It is easy to remove that code since I have not gotten very far. I get another error that makes no sense but I have gotten the central to initiate pairing!

  • I checked library just in case but it is definitely nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib in source files but somehow it doesn't seem to find sd_ functions. If you could upload project/sln files, that will be much appreciated. It must be some simple setting somewhere I don't understand..

  • I can't attach files here so I will send it to you in an email

Reply Children
  • Turns out that it was because you used a cpp (C++) file and the example is in C. Changing the the cpp to c in the file created by the VS Console app solves the problem - for anyone else who stumbles on the same problem. (One of those things you don't think about when using the VS shell project creators).

    There is another issue that caused my library problems. Even though its a static library I linked to, if I set the project properties CodeGeneration settings to use static linking, the project will not build. I get all kinds of warning conflicts about already imported libraries by the Nordic static library which eventually become warnings. So the only way to build the project is to set the code generation to dynamic (dll) linking.

    Needless to say, I do not understand why that is so.

    But if I do, I can use the property pages to point to the Nordic static library instead of bringing it into my source or lib 'filter' folder in my project.

Related