Nick
Nick

Reputation: 3435

How to use static library (windows phone 8)

I cannot get static library linked against .exe application in MSVC-2013 for Windows Phone 8.0.

What I did:

  1. File->New->Project->DirectX App (Windows Phone 8.0) -> Name it "MyApp".

    This template creates nice application that compiles and run without problems.

  2. Right click on solution->Add->New Project->Static Library (Windows Phone 8.0). Let's call it "MyLib".

  3. Right click on MyApp -> Build Dependencies -> Project Dependencies -> Make it dependent on MyLib.

    Still compiles and runs.

  4. Go to MyLib.h and declare int my_function(int x).

  5. Go to MyLib.cpp and define int my_function(int x) {return 0;}.

  6. #include "MyLib.h" in MyApp's CubeRenderer.cpp.

  7. Add int y = my_function(6); in CubeRenderer::CubeRenderer() in CubeRenderer.cpp.

This produces linker error.

error LNK2019: unresolved external symbol "int __cdecl my_function(int)" (?my_function@@YAHH@Z) 

MyApp depends on MyLib, so I do not need to set in Linker->Input->Addidtional Dependencies. Anyway, I have tried it and still get the error.

I have searched for ?my_function@@YAHH@Z in MyLib.lib - and found it 5 times there.

Maybe I cannot use template named Static Library (Windows Phone 8.0) and should use DLL (Windows Phone 8.0) or Windows Runtime Component (Windows Phone 8.0)?

Upvotes: 0

Views: 537

Answers (1)

user1861757
user1861757

Reputation: 26

You need to add a Project to Project reference to make this build. You can add this by right clicking the project Add->References and click Add New Reference and add MyLib to MyApp as a project to project reference.

Upvotes: 1

Related Questions