aslze / asl

A compact C++ cross-platform library including JSON, XML, HTTP, Sockets, WebSockets, threads, processes, logs, file system, CSV, INI files, vectors and matrices, etc.
Other
69 stars 17 forks source link

Dynamic library load does not add ".dll" to the library name #25

Closed dezashibi closed 1 year ago

dezashibi commented 1 year ago

I've been using the library in the project and I've noticed that despite mentioned in the documentation and as I've checked in the code the extension at least on windows is not added to the string.

here I've setup a completely fresh example for this:

set(CMAKE_CXX_STANDARD 17) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(LIB_NAME my_lib)

add_library(${LIB_NAME} SHARED my_lib.cpp) target_link_libraries(${LIB_NAME} PUBLIC asls)

add_executable(${PROJECT_NAME} loader.cpp) target_link_libraries(${PROJECT_NAME} PUBLIC asls)


- `loader.cpp`
```cpp
// loader.cpp
#include <asl/Library.h>

#include "my_lib.h"
#include <iostream>

int main()
{
        // asl::Library lib("my_lib.dll"); // this works as expected
    asl::Library lib("my_lib"); // this causes lib is not loaded error

    if (!lib.loaded())
    {
        std::cout << "lib is not loaded" << std::endl;
        return -1;
    }

    auto* l = (MyLib*)lib.create("MyLib");

    if (l == nullptr)
    {
        std::cout << "MyLib is not found" << std::endl;
        return -1;
    }

    std::cout << l->get_number() << std::endl;

    delete l;

    return 0;
}

include "asl/Library.h"

class MyLibBase { public: virtual int get_number() = 0; };

class MyLib : public MyLibBase { public: int get_number() override; };


- `my_lib.cpp`
```cpp
#include "my_lib.h"

int MyLib::get_number()
{
    return 36;
}

ASL_EXPORT_CLASS(MyLib)

UPDATE: it seems in Library.h line 132, we need to do like file += "." ASL_LIB_EXT; because we don't have . for sure or change the macros to include . as well.

dezashibi commented 1 year ago

submitted PR in here: https://github.com/aslze/asl/pull/26