DigitalInBlue / Celero

C++ Benchmark Authoring Library/Framework
Other
823 stars 96 forks source link

Static library built in VS2015 doesn't work #99

Closed everyonecancode closed 7 years ago

everyonecancode commented 7 years ago

Hi, I tried to create static library only build with VS2015. I received the .lib file (around 14MB), but when I tried to complle your runnable example, I received LNK2019 errors (log file attached). However, the same example, compiled with dynamic libs (40KB celero.lib and ~1MB celero.dll) builds and runs without a problem.

build.txt

DigitalInBlue commented 7 years ago

Did you compile with the CMake variable CELERO_COMPILE_DYNAMIC_LIBRARIES set to OFF? If you did, there should be a precompiler definition of CELERO_STATIC for all of your projects. When that is set, Export.h is supposed to give blank definitions to CELERO_EXPORT and CELERO_EXPORT_C. When this is true, you will not have __declspec(dllimport) used in your project, but this is exactly what I see in your log file. Check to make sure CELERO_STATIC is defined in all of your projects.

everyonecancode commented 7 years ago

While adding CELERO_STATIC did fix _declspec(dllimport) errors, I've got a new one:

celerod.lib(Utilities.obj) : error LNK2019: unresolved external symbol CallNtPowerInformation referenced in function "void __cdecl celero::DisableDynamicCPUScaling(void)" (?DisableDynamicCPUScaling@celero@@YAXXZ)

Again, same code (from the example you provided), works with dll build.

DigitalInBlue commented 7 years ago

See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa372675(v=vs.85).aspx

Looks like PowrProf.lib needs to be included. (I haven't actually built with static libraries myself.)

everyonecancode commented 7 years ago

Yes, adding PowrProf.lib fixed this issue.

Will you fix the static build or just advise against using it? Either way, I think it would be a good idea to update the README file on project's page.

DigitalInBlue commented 7 years ago

Great. I will update the CMakeList.txt and push the change. Thanks for the debugging help.

On Tue, Mar 7, 2017 at 12:32 PM, everyonecancode notifications@github.com wrote:

Yes, adding PowrProf.lib fixed this issue.

Will you fix the static build or just advise against using it? Either way, I think it would be a good idea to update the README file on project's page.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DigitalInBlue/Celero/issues/99#issuecomment-284796259, or mute the thread https://github.com/notifications/unsubscribe-auth/ADF0DOgpfgKRPkdwLvpeq3b-_n6e0pgZks5rjZSQgaJpZM4LrJR0 .

everyonecancode commented 7 years ago

No problem. Thank you for creating this great library :)

zamazan4ik commented 7 years ago

Can you close this issue?

MichaelMauderer commented 6 years ago

Has this actually been fixed? I just ran into this issue (Visual Studio 14 2015 Win64) with the current version.

DigitalInBlue commented 6 years ago

Was the issue that "PowrProf.lib" was not linked or is your problem a new issue?

MichaelMauderer commented 6 years ago

Yeah exactly. I got it fixed for our build, but it seems that the current fix in the Celero CMake file didn't work for me.

DigitalInBlue commented 6 years ago

Ok. Can you push your fix up? Sorry. I don't use it statically and didn't know it was broken still.

MichaelMauderer commented 6 years ago

I only fixed the issue locally by adding a target_link_libraries(PROJECTNAME PowrProf.lib) to our build. I am not sure why the one from the Celero CMakeLists.txt did not do the job though.