Right way to set up vc++ project with libraries in Visual Studio 2017












-1















I have a vc++ project that makes use of compiled library(freeglut in my case).Library consists of headers(.h) and 64/32bit libraries (.lib and .dll). I managed to get it working by dropping dll's in system32/sysWOW64 and setting absolute path to include and lib directories. But I'd like to know the proper way to set up linker and/or project dependencies in Visual Studio 17 so that all needed files can be inside project directory (relative path) and 64/32bit and Release/Debug builds worked. Thank you.










share|improve this question























  • These support DLLs have very little to do with your project. They just need to be found when you run your program, that's all. Putting them in the OS directory is not very appropriate, imagine somebody else doing that on your user's machine and, invariably, copy a different version. Proper way is a post-build event that uses xcopy /d to copy them to $(OutDir).

    – Hans Passant
    Nov 23 '18 at 20:09
















-1















I have a vc++ project that makes use of compiled library(freeglut in my case).Library consists of headers(.h) and 64/32bit libraries (.lib and .dll). I managed to get it working by dropping dll's in system32/sysWOW64 and setting absolute path to include and lib directories. But I'd like to know the proper way to set up linker and/or project dependencies in Visual Studio 17 so that all needed files can be inside project directory (relative path) and 64/32bit and Release/Debug builds worked. Thank you.










share|improve this question























  • These support DLLs have very little to do with your project. They just need to be found when you run your program, that's all. Putting them in the OS directory is not very appropriate, imagine somebody else doing that on your user's machine and, invariably, copy a different version. Proper way is a post-build event that uses xcopy /d to copy them to $(OutDir).

    – Hans Passant
    Nov 23 '18 at 20:09














-1












-1








-1








I have a vc++ project that makes use of compiled library(freeglut in my case).Library consists of headers(.h) and 64/32bit libraries (.lib and .dll). I managed to get it working by dropping dll's in system32/sysWOW64 and setting absolute path to include and lib directories. But I'd like to know the proper way to set up linker and/or project dependencies in Visual Studio 17 so that all needed files can be inside project directory (relative path) and 64/32bit and Release/Debug builds worked. Thank you.










share|improve this question














I have a vc++ project that makes use of compiled library(freeglut in my case).Library consists of headers(.h) and 64/32bit libraries (.lib and .dll). I managed to get it working by dropping dll's in system32/sysWOW64 and setting absolute path to include and lib directories. But I'd like to know the proper way to set up linker and/or project dependencies in Visual Studio 17 so that all needed files can be inside project directory (relative path) and 64/32bit and Release/Debug builds worked. Thank you.







c++ visual-studio visual-c++






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 19:45









Je_dayJe_day

1




1













  • These support DLLs have very little to do with your project. They just need to be found when you run your program, that's all. Putting them in the OS directory is not very appropriate, imagine somebody else doing that on your user's machine and, invariably, copy a different version. Proper way is a post-build event that uses xcopy /d to copy them to $(OutDir).

    – Hans Passant
    Nov 23 '18 at 20:09



















  • These support DLLs have very little to do with your project. They just need to be found when you run your program, that's all. Putting them in the OS directory is not very appropriate, imagine somebody else doing that on your user's machine and, invariably, copy a different version. Proper way is a post-build event that uses xcopy /d to copy them to $(OutDir).

    – Hans Passant
    Nov 23 '18 at 20:09

















These support DLLs have very little to do with your project. They just need to be found when you run your program, that's all. Putting them in the OS directory is not very appropriate, imagine somebody else doing that on your user's machine and, invariably, copy a different version. Proper way is a post-build event that uses xcopy /d to copy them to $(OutDir).

– Hans Passant
Nov 23 '18 at 20:09





These support DLLs have very little to do with your project. They just need to be found when you run your program, that's all. Putting them in the OS directory is not very appropriate, imagine somebody else doing that on your user's machine and, invariably, copy a different version. Proper way is a post-build event that uses xcopy /d to copy them to $(OutDir).

– Hans Passant
Nov 23 '18 at 20:09












2 Answers
2






active

oldest

votes


















0














The usual hierarchy for an installed library is the following:




  • bin <- this is where you put the dll file, and you should add the path to the PATH environment variable

  • include <- this is where you put the header files

  • lib <- this is where you put the definition libraries (.lib).


Set then something like %MY_LIBRARY_PATH% to the folder where you have these three folders.



Then in your project, you can set the include path like %MY_LIBRARY_PATH%/include and the library to link with to %MY_LIBRARY_PATH%/lib/mylibary.lib in the properties of your project. It is possible to refine the latter to get the path in the list of the folders to explorer and then you only specify mylibrary.lib as the file to link to.






share|improve this answer
























  • Thanks. That’s should do for my ptoject. How hard would it be to set up vs project template to accommodate a project like that? Microsoft docs weren’t really specific for vc++ project.

    – Je_day
    Nov 24 '18 at 5:42











  • Usually, I set up this through CMake which generates my VS solution. I don't think there is a template for this, as it's on third party libraries, and not your current project. If you have several libraries, there is no way to set up a template.

    – Matthieu Brucher
    Nov 24 '18 at 9:26



















0














If it is a library you are going to want to use in many projects use the "Property Manager" window found under View->Other Windows rather than changing the properties for every project.



Open the debug node for each platform type and then right click on Microsoft.Cpp..User and select "Properties". You can then edit the user specified properties that are imported into every project for your user on that particular computer. You will want to add the paths under the "VC++ directories" node, in particular the "Include dictories" and "Library directories" lines.



Note that you should not simply copy files into the windows directory tree, choose some place else for files that are not managed by an installer (I use :DevTools as a catch-all for this kind of thing). As another answer says if DLLs are involved you will also want to edit the PATH environment variable to include such a directory (this is in addition to the properties changes mentioned above).






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452218%2fright-way-to-set-up-vc-project-with-libraries-in-visual-studio-2017%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The usual hierarchy for an installed library is the following:




    • bin <- this is where you put the dll file, and you should add the path to the PATH environment variable

    • include <- this is where you put the header files

    • lib <- this is where you put the definition libraries (.lib).


    Set then something like %MY_LIBRARY_PATH% to the folder where you have these three folders.



    Then in your project, you can set the include path like %MY_LIBRARY_PATH%/include and the library to link with to %MY_LIBRARY_PATH%/lib/mylibary.lib in the properties of your project. It is possible to refine the latter to get the path in the list of the folders to explorer and then you only specify mylibrary.lib as the file to link to.






    share|improve this answer
























    • Thanks. That’s should do for my ptoject. How hard would it be to set up vs project template to accommodate a project like that? Microsoft docs weren’t really specific for vc++ project.

      – Je_day
      Nov 24 '18 at 5:42











    • Usually, I set up this through CMake which generates my VS solution. I don't think there is a template for this, as it's on third party libraries, and not your current project. If you have several libraries, there is no way to set up a template.

      – Matthieu Brucher
      Nov 24 '18 at 9:26
















    0














    The usual hierarchy for an installed library is the following:




    • bin <- this is where you put the dll file, and you should add the path to the PATH environment variable

    • include <- this is where you put the header files

    • lib <- this is where you put the definition libraries (.lib).


    Set then something like %MY_LIBRARY_PATH% to the folder where you have these three folders.



    Then in your project, you can set the include path like %MY_LIBRARY_PATH%/include and the library to link with to %MY_LIBRARY_PATH%/lib/mylibary.lib in the properties of your project. It is possible to refine the latter to get the path in the list of the folders to explorer and then you only specify mylibrary.lib as the file to link to.






    share|improve this answer
























    • Thanks. That’s should do for my ptoject. How hard would it be to set up vs project template to accommodate a project like that? Microsoft docs weren’t really specific for vc++ project.

      – Je_day
      Nov 24 '18 at 5:42











    • Usually, I set up this through CMake which generates my VS solution. I don't think there is a template for this, as it's on third party libraries, and not your current project. If you have several libraries, there is no way to set up a template.

      – Matthieu Brucher
      Nov 24 '18 at 9:26














    0












    0








    0







    The usual hierarchy for an installed library is the following:




    • bin <- this is where you put the dll file, and you should add the path to the PATH environment variable

    • include <- this is where you put the header files

    • lib <- this is where you put the definition libraries (.lib).


    Set then something like %MY_LIBRARY_PATH% to the folder where you have these three folders.



    Then in your project, you can set the include path like %MY_LIBRARY_PATH%/include and the library to link with to %MY_LIBRARY_PATH%/lib/mylibary.lib in the properties of your project. It is possible to refine the latter to get the path in the list of the folders to explorer and then you only specify mylibrary.lib as the file to link to.






    share|improve this answer













    The usual hierarchy for an installed library is the following:




    • bin <- this is where you put the dll file, and you should add the path to the PATH environment variable

    • include <- this is where you put the header files

    • lib <- this is where you put the definition libraries (.lib).


    Set then something like %MY_LIBRARY_PATH% to the folder where you have these three folders.



    Then in your project, you can set the include path like %MY_LIBRARY_PATH%/include and the library to link with to %MY_LIBRARY_PATH%/lib/mylibary.lib in the properties of your project. It is possible to refine the latter to get the path in the list of the folders to explorer and then you only specify mylibrary.lib as the file to link to.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 23 '18 at 19:56









    Matthieu BrucherMatthieu Brucher

    15.9k32141




    15.9k32141













    • Thanks. That’s should do for my ptoject. How hard would it be to set up vs project template to accommodate a project like that? Microsoft docs weren’t really specific for vc++ project.

      – Je_day
      Nov 24 '18 at 5:42











    • Usually, I set up this through CMake which generates my VS solution. I don't think there is a template for this, as it's on third party libraries, and not your current project. If you have several libraries, there is no way to set up a template.

      – Matthieu Brucher
      Nov 24 '18 at 9:26



















    • Thanks. That’s should do for my ptoject. How hard would it be to set up vs project template to accommodate a project like that? Microsoft docs weren’t really specific for vc++ project.

      – Je_day
      Nov 24 '18 at 5:42











    • Usually, I set up this through CMake which generates my VS solution. I don't think there is a template for this, as it's on third party libraries, and not your current project. If you have several libraries, there is no way to set up a template.

      – Matthieu Brucher
      Nov 24 '18 at 9:26

















    Thanks. That’s should do for my ptoject. How hard would it be to set up vs project template to accommodate a project like that? Microsoft docs weren’t really specific for vc++ project.

    – Je_day
    Nov 24 '18 at 5:42





    Thanks. That’s should do for my ptoject. How hard would it be to set up vs project template to accommodate a project like that? Microsoft docs weren’t really specific for vc++ project.

    – Je_day
    Nov 24 '18 at 5:42













    Usually, I set up this through CMake which generates my VS solution. I don't think there is a template for this, as it's on third party libraries, and not your current project. If you have several libraries, there is no way to set up a template.

    – Matthieu Brucher
    Nov 24 '18 at 9:26





    Usually, I set up this through CMake which generates my VS solution. I don't think there is a template for this, as it's on third party libraries, and not your current project. If you have several libraries, there is no way to set up a template.

    – Matthieu Brucher
    Nov 24 '18 at 9:26













    0














    If it is a library you are going to want to use in many projects use the "Property Manager" window found under View->Other Windows rather than changing the properties for every project.



    Open the debug node for each platform type and then right click on Microsoft.Cpp..User and select "Properties". You can then edit the user specified properties that are imported into every project for your user on that particular computer. You will want to add the paths under the "VC++ directories" node, in particular the "Include dictories" and "Library directories" lines.



    Note that you should not simply copy files into the windows directory tree, choose some place else for files that are not managed by an installer (I use :DevTools as a catch-all for this kind of thing). As another answer says if DLLs are involved you will also want to edit the PATH environment variable to include such a directory (this is in addition to the properties changes mentioned above).






    share|improve this answer




























      0














      If it is a library you are going to want to use in many projects use the "Property Manager" window found under View->Other Windows rather than changing the properties for every project.



      Open the debug node for each platform type and then right click on Microsoft.Cpp..User and select "Properties". You can then edit the user specified properties that are imported into every project for your user on that particular computer. You will want to add the paths under the "VC++ directories" node, in particular the "Include dictories" and "Library directories" lines.



      Note that you should not simply copy files into the windows directory tree, choose some place else for files that are not managed by an installer (I use :DevTools as a catch-all for this kind of thing). As another answer says if DLLs are involved you will also want to edit the PATH environment variable to include such a directory (this is in addition to the properties changes mentioned above).






      share|improve this answer


























        0












        0








        0







        If it is a library you are going to want to use in many projects use the "Property Manager" window found under View->Other Windows rather than changing the properties for every project.



        Open the debug node for each platform type and then right click on Microsoft.Cpp..User and select "Properties". You can then edit the user specified properties that are imported into every project for your user on that particular computer. You will want to add the paths under the "VC++ directories" node, in particular the "Include dictories" and "Library directories" lines.



        Note that you should not simply copy files into the windows directory tree, choose some place else for files that are not managed by an installer (I use :DevTools as a catch-all for this kind of thing). As another answer says if DLLs are involved you will also want to edit the PATH environment variable to include such a directory (this is in addition to the properties changes mentioned above).






        share|improve this answer













        If it is a library you are going to want to use in many projects use the "Property Manager" window found under View->Other Windows rather than changing the properties for every project.



        Open the debug node for each platform type and then right click on Microsoft.Cpp..User and select "Properties". You can then edit the user specified properties that are imported into every project for your user on that particular computer. You will want to add the paths under the "VC++ directories" node, in particular the "Include dictories" and "Library directories" lines.



        Note that you should not simply copy files into the windows directory tree, choose some place else for files that are not managed by an installer (I use :DevTools as a catch-all for this kind of thing). As another answer says if DLLs are involved you will also want to edit the PATH environment variable to include such a directory (this is in addition to the properties changes mentioned above).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 20:27









        SoronelHaetirSoronelHaetir

        6,9941514




        6,9941514






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452218%2fright-way-to-set-up-vc-project-with-libraries-in-visual-studio-2017%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin