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?

  • 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)
     

  • Hi,

    Here are the steps I used to compile the project with VS Studio 2017:

    1. New project -> Visual C++ -> Windows Console Application -> OK
    2. In ConesoleApplication.cpp, I replaced the content with this one -> https://github.com/NordicSemiconductor/pc-ble-driver/blob/master/examples/heart_rate_collector/main.c
    3. In the Solution Explorer, right click on ConsoleApplication -> Properties -> VC++ Directories -> “Include Directories” -> Edit ->  New line, find the pc-ble-driver include folder , (e.g. C:\Nordic\nrf-ble-driver-4.1.1-win_x86_32 \include\sd_api_v6) -> OK.
    4. In the Solution Explorer, right click on ConsoleApplication -> Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions -> Edit-> By default there are “WIN32, _DEBUG and _CONSOLE. Add:

      PC_BLE_DRIVER_STATIC

       _CRT_SECURE_NO_WARNINGS

      NRF_SD_BLE_API=6  
    5. In the Solution Explorer, right click on ConsoleApplication -> Properties -> C/C++ -> Precompiled Headers -> Precompiled Header -> Set to “Not using precompiled Headers”.
    6. In the Solution Explorer, right click on Header Files -> Add -> Existing Item.. -> Mark all the .h files in folder “nrf-ble-driver-4.1.1-win_x86_32\include\sd_api_v6”, there should be 18 files -> OK.
    7. In the Solution Explorer, right click on “Source Files”, Add -> Existing Item.. -> Find the lib folder, and add nrf-ble-driver-sd_api_v6-mt-static-4_1_1.lib -> OK
    8. Build -> Build Solution
  • 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.

Related