Failed to link C ++ static library

I figured out how to install VC ++ to compile the code into a .lib file, not a .exe, but I had problems connecting lib to my other .obj files.

This is how I set up the library and application folders. (I'm not sure if this is correct)

AppFolder
  App.sln
  App.ncb
  *.h
  *.cpp
  Debug
    *.obj
    App.exe

and somewhere else on the hard drive ...

LibraryFolder
  lib
    Library.lib
  include
    LibrarySolutionFolder
      Library.sln
      Library.ncb
      *.h
      *.cpp
      Debug
        *.obj
        Library.lib

I was # including a library of * .h files from my cpp app files and everything compiles fine. It's just that when it binds, I get a list of all the .lib files that are being viewed, and Library.lib does not exist, although I listed them in the VC ++ directories. How can I relate this? (And did I properly structure the library folders correctly?)

+3
source share
5 answers

In the project properties:

→ Linker → Input → Additional Dependancies

.

, .h , :

#pragma comment(lib, "Library")

.

+10

V++ - , . , .

lib Project Linker.

+3

, :

  • Project- > Properties...- > Linker, Input- > Additional Dependancies  ( V++ .lib, ),
  • . ( , → → ...), Project → Project Dependancies..., (, ). , , , V++ , .
  • , V++,

      #pragma comment(lib,"C:\\path\\to\\library.lib")`
    

    ( @Nils)

. ​​ "include": *.h( #include d).

+1

:

cl/EHsc {objfiles} +/link /LIBPATH: LibraryFolder Library.lib

{objfiles} + cpp.

+1

VC , .

, . : . MSVC , , .

, .

VC . ( ).

#pragma comment(lib,"c:\\path_to_library\\libname.lib")

, lib, MSVC.

Another way is to simply add the linker to the project settings. In the relevant information you can find the linker options for your project. Remember to add lib in the release and debug configurations.

0
source

Source: https://habr.com/ru/post/1698548/


All Articles