0

Under C++Builder, I am having an error at link step while trying to use static library libsodium.lib.

The test under Visual Studio works fine.

Any idea to help ?

This is my code :

// C++ Builder

//...
#define SODIUM_STATIC
extern "C" {
#include <sodium.h>
}

void __fastcall TForm1::FormShow(TObject *Sender)
{//
 if (sodium_init() < 0) Edit1->Text = L"Failure"; else Edit1->Text = L"Success";
}

//=> Linker message = unresolved external symbol '_sodium_init'

// Visual C++
//...
#define SODIUM_STATIC
#include <sodium.h>

int main()
{//
 if (sodium_init() < 0) {std::cout << "Failure" << std::endl; return 1;}
 std::cout << "Success" << std::endl;
 return 0;
}

=> Working fine !

ibouka
  • 13
  • 1
  • 5
  • 1
    Sounds like you didn't add the `.lib` file to your C++Builder project. However, note that `.lib` files are compiler-specific. You can't use Visual Studio `.lib` files in C++Builder. If this is an import lib for a DLL, you need to create a new `.lib` file for C++Builder using its [`IMPLIB`](https://docwiki.embarcadero.com/RADStudio/en/IMPLIB.EXE,_the_Import_Library_Tool_for_Win32) (32bit) or [`MKLIB`](https://docwiki.embarcadero.com/RADStudio/en/MKEXP.EXE,_the_64-bit_Windows_Import_Library_Tool_for_C%2B%2B) (64bit) tool – Remy Lebeau Aug 30 '23 at 01:14
  • Thank you so much @RemyLebeau. Now all is working perfectly. I begun with compiling the `.dll` as new `.lib` using implib. Afterwards, I added the `.dll` to the project and completed the above code with `#pragma comment(lib, "LIBSodium.lib")`. Previously, the path of the .lib had been added to the include paths. – ibouka Aug 30 '23 at 15:19
  • Adding the lib path to the include path doesn't tell the linker to look for the lib file. It has to actually be in the project. – Remy Lebeau Aug 30 '23 at 15:40

0 Answers0