Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Visual Studio: Creating A Console Project And Linking To 3'rd Party Libraries

Visual Studio Console App Linking Header including OpenCV Creating Project Libraries console

  • Please log in to reply
No replies to this topic

#1 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 28 May 2012 - 12:52 AM

Abstract
While answering on C/C++ threads, I needed to provide links to, "How to create a project in Visual Studio", "How to include 3'rd party headers", "How to link to 3'rd party libraries" type answers. This tutorial is about putting answers for all the 3 questions. All the following steps are same for Visual Studio 2005/2008/2010.


Creating an Empty Console Application
  • Lunch Visual Studio. Click on "File -->New-->Project".
  • On the 'New Project' wizard, select 'Visual C++ -->Win32' from the 'Project Type' section (left side of the wizard). Then select 'Win32 Console Application' from 'Template' section (right side of the wizard) and give a name of your project in the 'Name' textbox (suppose TestProject) and finally click on 'OK' button.
  • Now 'Win32 Application' wizard will appear. Click on 'Application Settings' form left side. Check the 'Empty Project' option from 'Additional Options' section and click on 'Finish' button.
  • In the solution explorer, right click on your project node (TestProject) --> Add --> New Item. 'Add New Item' wizard will appear. Select 'C++ File (.cpp)' from 'Template' section. Give a name of the file (main.cpp) and click on 'Add' button.
  • An empty, named main.cpp, will get added in the project. Put this code in the project. This is a hello world example of C++.
    #include <iostream>	
    	using namespace std;	
    		
    	int main()	
    	{	
    	cout << "Hellow C++ World!";	
    	return 0;	
    	}


How to Include 3'rd Party Headers
  • Right click on project -- > Properties --> Configuration Properties --> C/C++--> General
  • Select the 'Additional Dependencies" property node and then Click the on the 3 dotted (...) button
  • Then on the 'Additional Include Directories" popup, input all the paths for the 3'rd party headers on the top textbox and click on 'Ok' button
  • Click on 'Apply' button.
As example, I installed OpenCV at "D:\OpenCV\cv_binary\install" on my machine. So I added "D:\OpenCV\cv_binary\install\Include" path in step 3.


How to Link to 3'rd Party Libraries
  • Right click on project -- > Properties --> Configuration Properties --> Linker-->General
  • Select the "Additional Library Directories" property node and then Click the on the 3 dotted (...) button
  • In the "Additional Library Directories" popup, input all the directories of libraries you want to link to.
  • Select Configuration Properties --> Linker--> Input
  • Select the 'Additional Dependencies" property node and then Click the on the 3 dotted (...) button
  • Then on the 'Additional Dependencies" popup, input all the libraries you want to link to on the top textbox and click on 'Ok' button
  • Click on 'Apply' button and re-compile your application.
So to link to OpenCV libraries, I added "D:\OpenCV\cv_binary\install\lib" path in step 3. Then in step 6, I added 'opencv_core231d', 'opencv_ml231d', 'opencv_video231d' and other libraries.
  • 0





Also tagged with one or more of these keywords: Visual Studio, Console App, Linking, Header including, OpenCV, Creating Project, Libraries, console

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download