<p dir="ltr"><br>
On Apr 25, 2016 6:41 PM, "J. Caleb Wherry" <<a href="mailto:calebwherry@gmail.com">calebwherry@gmail.com</a>> wrote:<br>
><br>
> (1)<br>
><br>
> You typically want to define the entry point in the source itself. You can use the 'CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS' in CMake but you usually do something like this in the source:<br>
><br>
> #ifdef WIN32<br>
> #define PUBLIC_API __declspec(dllexport)<br>
> #else<br>
> #define PUBLIC_API<br>
> #endif<br>
><br>
> PUBLIC_API void HelloFunc();<br>
><br>
> That way when you are building a shared lib on windows it will export those symbols which in turn creates the .lib. Without the exported symbols, you will not have an import lib.<br>
><br>
> (2)<br>
><br>
> The missing DLL is a pain that you are just going to have to deal with unless you want to do a bunch of voodoo with the registry or copy the DLLs. Typically, there are POST_BUILD steps that copy the needed DLLs into the same directory as the exe. There are many stackoverflow questions dealing with this, first one googled here:<br>
></p>
<p dir="ltr">Could just set the path environment variable... No registry hack.. Or include install rules and just build install before running.<br>
> <a href="http://stackoverflow.com/questions/5765986/how-can-i-run-an-exe-with-dlls-in-separate-directory">http://stackoverflow.com/questions/5765986/how-can-i-run-an-exe-with-dlls-in-separate-directory</a><br>
><br>
> -Caleb<br>
><br>
><br>
> On Mon, Apr 25, 2016 at 9:01 PM, Chaos Zhang <<a href="mailto:zcsd2012@gmail.com">zcsd2012@gmail.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I faced this problem when i try built a shared lib  and linked it on<br>
>> windows. The structure of my project as below:<br>
>> -test_dir/<br>
>>      -sub_hello/<br>
>>            CMakeLists.txt<br>
>>            hello.c<br>
>>      -top/<br>
>>            main.c<br>
>>            CMakeLists.txt<br>
>>      CMakeLists.txt<br>
>><br>
>> The content of each file:<br>
>> ①test_dir/CMakeLists.txt:<br>
>> PROJECT(TESTLIB)<br>
>> add_subdirectory(sub_hello sub_hello)<br>
>> add_subdirectory(top top)<br>
>><br>
>> ②test_dir/sub_hello/CMakeLists.txt:<br>
>> message("message from sub_hello")<br>
>> add_library(hello_lib  SHARED hello.c)<br>
>><br>
>> ③test_dir/top/CMakeLists.txt:<br>
>> include_directories(../sub_hello)<br>
>> add_executable(main main.c)<br>
>> target_link_libraries(main hello_lib)<br>
>><br>
>> ④test_dir/sub_hello/hello.c:<br>
>> #include <stdio.h><br>
>> void HelloFunc()<br>
>> {<br>
>>         printf("###hello###\n");<br>
>> }<br>
>><br>
>> ⑤test_dir/top/main.c:<br>
>> int main()<br>
>> {<br>
>>         HelloFunc();<br>
>>         return 0;<br>
>> }<br>
>><br>
>> After i cmake this project, generated .sln and .proj files, then i built it<br>
>> and i get an error in vs:<br>
>><br>
>> Error   LNK1104 can't open file "..\sub_hello\Debug\hello_lib.lib"<br>
>><br>
>> In folder ..\sub_hello\Debug\ , there was not a hello_lib.lib existed.<br>
>> Then i look thorough and found a solution:<br>
>><br>
>> Add "set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS YES)" in file<br>
>> test_dir/sub_hello/hello.c<br>
>><br>
>> Then i built this solution again, this time it success, and hello_lib.lib<br>
>> and main.exe was generated. But when i try to run main.exe, an error<br>
>> occured: "lose hello_lib.dll". And i moved hello_lib.dll into the folder of<br>
>> main.exe, and it worked well.<br>
>><br>
>> There are two questions i could not figure out:<br>
>> ①Is this "..\sub_hello\Debug\hello_lib.lib" associates with<br>
>> "..\sub_hello\Debug\hello_lib.dll"? For windows can not use .dll directly,<br>
>> and use a .lib to record the .dll's  entrance and location.<br>
>> ②How to solve the problem of main.exe can not find .dll file.<br>
>><br>
>> Best regards,<br>
>> Chao Zhang<br>
>><br>
>><br>
>><br>
>><br>
>><br>
>> --<br>
>> View this message in context: <a href="http://cmake.3232098.n2.nabble.com/How-to-link-shared-lib-on-windows-visual-studio-2014-tp7593346.html">http://cmake.3232098.n2.nabble.com/How-to-link-shared-lib-on-windows-visual-studio-2014-tp7593346.html</a><br>
>> Sent from the CMake mailing list archive at Nabble.com.<br>
>> --<br>
>><br>
>> Powered by <a href="http://www.kitware.com">www.kitware.com</a><br>
>><br>
>> Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
>><br>
>> Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
>><br>
>> CMake Support: <a href="http://cmake.org/cmake/help/support.html">http://cmake.org/cmake/help/support.html</a><br>
>> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html">http://cmake.org/cmake/help/consulting.html</a><br>
>> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html">http://cmake.org/cmake/help/training.html</a><br>
>><br>
>> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br>
>><br>
>> Follow this link to subscribe/unsubscribe:<br>
>> <a href="http://public.kitware.com/mailman/listinfo/cmake">http://public.kitware.com/mailman/listinfo/cmake</a><br>
><br>
><br>
><br>
><br>
> -- <br>
> J. Caleb Wherry<br>
> Scientific Software Engineer<br>
><br>
> <a href="http://www.calebwherry.com">http://www.calebwherry.com</a><br>
> +1 (615) 708-5651<br>
> <a href="mailto:calebwherry@gmail.com">calebwherry@gmail.com</a><br>
><br>
> --<br>
><br>
> Powered by <a href="http://www.kitware.com">www.kitware.com</a><br>
><br>
> Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
><br>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
><br>
> CMake Support: <a href="http://cmake.org/cmake/help/support.html">http://cmake.org/cmake/help/support.html</a><br>
> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html">http://cmake.org/cmake/help/consulting.html</a><br>
> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html">http://cmake.org/cmake/help/training.html</a><br>
><br>
> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/cmake">http://public.kitware.com/mailman/listinfo/cmake</a><br>
</p>