Link Outside Library in VS2013

Started by
1 comment, last by Khatharr 7 years, 11 months ago

I'm trying to link an outside library in my C++ VS2013 project. Upon compiling the project I get the error:

Error 1 error LNK2019: unresolved external symbol "void __cdecl bar(void)" (?bar@@YAXXZ) referenced in function _main D:\Projects\IncludeOutsideLib\main.obj IncludeOutsideLib

I have setup Configuration Properties->C/C++->Additional Include Directories to point to the outside library folder`$(PROJECTDIR)/../Foo/`. Is there anything else I need to do?

The project/directory structure is very simple


Projects:
    Foo:
        foo.h
        foo.cpp
    IncludeOutsideLib:
        // contains C++ VS2013 project
        main.cpp

foo.h:


   #ifndef FOO_H
    #define FOO_H

    #include <cstdlib>

    void bar();

    #endif // FOO_H

foo.cpp:


#include "foo.h"

    void bar()
    {
        printf("bar\n");
    }

main.cpp:


#include <iostream>
    #include <cstdlib>
    #include "foo.h"

    int main(int argc, char** argv)
    {
        bar();
        system("pause");
        return 0;
    }
Advertisement

You need your main project to link to the .lib file that you generated.

The best way is to make the lib project a dependency of the main project (Project menu -> Project Dependencies... and set up the main project to Depend On the lib project). Then make sure your main project has the Link Dependencies option enabled (Project properties -> Linker section -> set Link Library Dependencies to Yes).

That should fix the problem.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

I believe you can now add libs as resources in the Solution Explorer as well. I know that works in 2015CE.

It's nice for local libs but not so nice for system libs. I wish they'd improve that a bit more. I hate digging around in the properties pages.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement