My C++ library depends on boost_filesystem. I am working on windows 10 with Visual Studio 2022. I have built a python interface for my library using Cython. When I invoke Cython it complains that it can't find "libboost_file_system-vc...". The problem is that the "lib" prefix refers to the static library whereas I'm trying to link dynamically to "boost_file_system-vc...". I can work around the problem and get a working interface if I create a copy of "boost_file_system-vc..." with the "lib" prefix added" but this is clearly the wrong way to solve this problem. From what I've been able to determine so far, to do it correctly, I need to set the compiler flag '/D BOOST_ALL_DYN_LINK=1' but it seems I'm going about this the wrong way, or perhaps there's more to the solution than I'm aware. I've looked at related posts for help but so far nothing I've seen is answering the question for me.
Here is my setup.py:
from setuptools import setup, Extension
from Cython.Build import cythonize
import os
from sys import platform
if platform == "win32":
boostlib = 'boost_filesystem-vc143-mt-x64-1_78'
elif platform == "linux" or platform == "linux2":
boostlib = 'boost_filesystem'
ext = [Extension(name = "*",
sources = [os.path.join(os.path.dirname(__file__), "src", "*.pyx")],
extra_compile_args = [ '/D BOOST_ALL_DYN_LINK=1' ],
language = "c++",
library_dirs = ['../../build/install/bin','../../build/install/lib','../../Dependencies/build/install/lib',],
libraries = ['mylib',boostlib]
)
]
setup( name = "hemi",
ext_modules = cythonize(ext, language_level = "3"),
include_dirs = ['../include',
... # omitted lines
'../../Dependencies/build/install/include/boost-1_78',
'../../Dependencies/build/install/include'
],
)
I expected that adding the line specifying "extra_compile_args" would clue Cython into looking for the library with a name unprefixed by "lib", I.e. "boost_filesystem-vc..." rather than "libboost_filesystem_vc..." but I'm still getting the same error. What am I getting wrong/missing? Thanks!
defining
BOOST_ALL_DYN_LINKwas the right idea, but I was doing it in the wrong place apparently. Instead of the line shown in setup.py above I simply added the pre-processor macro#define BOOST_ALL_DYN_LINKin a top-level include file for the library I was building.