NVIDIA / AMGX

Distributed multigrid linear solver library on GPU
482 stars 139 forks source link

how to load library in a standard way #247

Open nooblegendliu opened 1 year ago

nooblegendliu commented 1 year ago

Hello. I am a beginner to use the AMGX library. My development environment includes VS, Win11, and CUDA v11.6. I have completed using the test case, and now I want to use this library in my own project. However, I am having trouble building it with static linking, as VS keeps giving me errors like "error LNK2001: unresolved external symbol __imp_AMGX_vector_set_zero". How can i fix it.

yanang007 commented 9 months ago

It would be more convenient to just link the dynamic library.

To link AMGX statically, you may try define AMGX_API_NO_IMPORTS in your build system or before amgx headers.

This is mainly caused by https://github.com/NVIDIA/AMGX/blob/716bcd597b44a0e546e1b9f90d7926f857131512/include/amgx_c.h#L31-L47 where __declspec( dllimport ) is added regardless of linking type.

But there probably do need a more specific macro to define whether is linking static lib instead of just AMGX_API_NO_IMPORTS.

Here is a typical example from pytorch where C10_CUDA_BUILD_SHARED_LIBS explicitly specifies the behavior.

#ifdef _WIN32
#if defined(C10_CUDA_BUILD_SHARED_LIBS)
#define C10_CUDA_EXPORT __declspec(dllexport)
#define C10_CUDA_IMPORT __declspec(dllimport)
#else
#define C10_CUDA_EXPORT
#define C10_CUDA_IMPORT
#endif
#else // _WIN32
// ...
#endif // _WIN32

// This one is being used by libc10_cuda.so
#ifdef C10_CUDA_BUILD_MAIN_LIB
#define C10_CUDA_API C10_CUDA_EXPORT
#else
#define C10_CUDA_API C10_CUDA_IMPORT
#endif