Thread: Custom libraries

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    20

    Custom libraries

    I'm making a little mess while creating custom libraries.

    I'm using Visual Studio 2019.

    I have some libraries that I'm going to use in lots of projects, so I created an external folder called lib in which I put header files (declarations) and .cpp files (definitions).

    In .cpp files I included every relative header using #include "name.h" and the same into every main.cpp in which I should use them.

    But the problem is: how does the complier find .cpp libraries if I never call them?

    So I discovered that I can right click on every single solution and >Add>Existing Project>H:\C++\lib\name.cpp

    But this is a bit frustrating to do in every project for every library that I want to include, since I already #include headers so I can't see why should I include libraries too.

    So the question is: is there a way to set another default folder in which Visual Studio could go to search for definitions like Standard Libraries or should I copy-past each .cpp into my solution to include it automatically?

    I don't understand why I can't find any solution onlinebacause it should be a very common problem!

  2. #2
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    302
    "without goto we would be wtf'd"

  3. #3
    Registered User
    Join Date
    Dec 2019
    Posts
    20
    Thank you! It helped a lot.

    Is there a way to set two different default directories for repositories and static libraries?

  4. #4
    Registered User
    Join Date
    Dec 2019
    Posts
    20
    Edit: it doesn't work.

    I include the static library into the solution but I get these errors:
    Code:
    Error    LNK1120    1    1 unresolved externals
    Error    LNK2019    1    unresolved external symbol "unsigned short __cdecl method1(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned short)" (?method1@@YAGABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@G@Z) referenced in function _main

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,926
    That sounds like either you didn't generate the static library file correctly, or you didn't link to it correctly. What exactly were the steps you took?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Dec 2019
    Posts
    20
    I created the project in an external folder dedicated to libraries.

    I compiled .cpp and .h files without deleting pch.cpp.

    I built the library in Build>Build Solution.

    I added the project to the main file solution (right click on solution>Add>Existing Project).

    I entered my libraries folder in Project>Properties>Common Properties>Debug Source Files.

    I wrote #include "name.h" in my main file.


    I also tried to create another project in the standard repository folder but it doesn't work anyway!

  7. #7
    Registered User
    Join Date
    Dec 2019
    Posts
    20
    Solved!

    After two hours I realized that I didn't link the projects adding a reference (right click on project>Add>Reference>Projects>name)


    Is there a way to set two different default directories for repositories and static libraries?
    If you could help me in this I can close the thread.

    I mean, when I create a new project or search for an existing one Visual Studio always sends me to the default repos path, but it would be smarter dividing libraries from console projects.
    Last edited by Foxel; 01-11-2020 at 05:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Custom Allocation
    By SevenThunders in forum C Programming
    Replies: 17
    Last Post: 04-09-2007, 04:10 PM
  2. Custom buttons
    By Lionmane in forum Windows Programming
    Replies: 2
    Last Post: 10-04-2005, 06:05 AM
  3. Custom UI
    By cfrost in forum Windows Programming
    Replies: 5
    Last Post: 08-20-2004, 12:52 PM
  4. custom library
    By lambs4 in forum C Programming
    Replies: 1
    Last Post: 06-09-2002, 04:58 AM
  5. custom encryption
    By XiReDDeViLiX in forum C++ Programming
    Replies: 2
    Last Post: 06-06-2002, 10:30 PM

Tags for this Thread