Settings for visual studio
Hello, may i know how am i supposed to compile it with visual studio? throws unresolved external symbols, i believe your code is not wrong, it's probably because of the compiler.
i'm not sure what you've tried, but this is a good starting point: https://cognitivewaves.wordpress.com/cmake-and-visual-studio/
once you have a solution file, you can build as normal in VS.
what are the symbols? it might be our code :)
If you have unresolved symbols you probably need to add shlwapi.lib to your linker inputs.
@BillyONeal Should the CMake be linking shlwapi.lib instead?
@EricWF: Don't know if it is possible to ask cmake to do that. See here:
https://github.com/google/benchmark/blob/6e259170011cd2fbac069b9d4ff83b42445a96cc/src/CMakeLists.txt#L36
The dependency on shlwapi.lib gets injected through a .obj that is packaged inside benchmark.lib (compiled from here), so it needs to be present on the linker command line for anyone who links against benchmark.lib.
(MSVC++ has #pragma comment(lib, "shlwapi.lib"), but I don't believe MinGW supports anything like that; so if folks are using CMake they're better off manually specifying it in their CMakeLists.txt)
Thanks Billy. I don't work on Windows so I'm trying to figure out if this is our bug, or just a general quirk of Windows compilation (like -pthread or -lm on Unix). If we ever get a CMake configuration module we should ensure shlwapi.lib is listed as an interface link library.
I think the best course of action is to prominently document the dependency as a known issue and close this bug.
@BillyONeal Patches correctly implementing #pragma comment(lib, "shlwapi.lib") are welcome. I would do it myself but I'm unfamiliar with Windows.
@EricWF: You can just stick that pragma in sysinfo.cc, and that lib will be added as a dependency for anyone who links against the resulting .obj. Putting it after #include <Shlwapi.h> should work: https://github.com/google/benchmark/blob/95dee3c699e0c972fca9ad414f80e451e0bf4d7f/src/sysinfo.cc#L19 -- but as I said I don't think that will work for MinGW targets.
@BillyONeal , can you explain to Nooglers who aren't used to using Cmake how I can manually link in Shlwapi into my projects CMakeLists?
Edit: figured it out. Just added "shlwapi.lib" to target_link_library command in my project. (Do add an example line of code, as I went on a wild goose chase to find the physical location of that file not knowing minGW had it on its regular path)
@winstondu In the same target_link_libraries where you add google test, just add shlwapi. I've been doing something like this:
function(add_benchmark BENCHNAME)
add_executable("${BENCHNAME}" "${PROJECT_SOURCE_DIR}/benchmarks/${BENCHNAME}.cpp")
target_link_libraries("${BENCHNAME}" benchmark)
if (MSVC)
target_link_libraries("${BENCHNAME}" Shlwapi.lib)
endif()
add_test("run_${BENCHNAME}" "${BENCHNAME}" "${BENCHMARK_OUTPUT_FORMAT}")
endfunction(add_benchmark)
Once i build the INSTALL.vcproj and RUN_TESTS , how do i link the library to a new VS project
@Cxx-mlr I have the same requirement to link the library to a new VS project. Did you get it working yet? If yes, can you please share the steps to do it?
If the benchmark project is generated with -DBUILD_SHARED_LIBS=on, it will work in Visual Studio - as long as the Additional Include Directories contain the benchmark/include folder and the Additional Library Directories contain the benchmark/lib folder.
There is no need to specify shlwapi.lib as additional dependency in the consuming project.
I don't think that the version being installed through vcpkg is build with shared libs on - I had to build it specifically off a forked version.
is there a way to change the vcpkg installer version to include shared libs?