开发者

basic instructions on how to create a .sln with simple C++ library (no .net use) and C++ project using that library?

I am C++ beginner. I have a simple console project. with class files inside that use boost (.libs) and openCV (dlls). I want to put all my existing classes into some namespace and into seperate projects. So I need a tutorial on how to separate开发者_运维技巧 my application project and code library in visual studio enviroment inside one sln?


First you create a new W32 Project (and solution) for your new executable (exe or dll). Choose save all (or else if something goes wrong, you'll lose everything).

After this you go to the solution explorer (in the right margin) and right-click on the solution-name (not the project). In the popup-menu choose Add->new Project.

Now you create a new w32 project (for a new library). In the Dialog that comes up you choose next and in the following page you choose static library (and some other options if want to). Now choose Finish and the new project will be added to the solution. Now choose save all.

Repeat these steps for all the libraries you want to create (and don't forget to save things).

You could build the solution now so that things exists. Next you must add the libraries to your executable-project.

Go to the properties of that project and select All Configurations in the combobox in the left-upper corner.

Now select the linker option and in there choose the input option. Now choose the additional libraries option in the property-page and in there choose edit. In the dialog that pops up you can add all libraries-names you just created. If you were to build now the linker will complain that it cannot find those libraries, so one more step is required.

In linker-options choose General and in the property-page there is a property Additional Library Paths. Here you must supply the path to all those libraries by choosing edit. In the dialog that pops up there is a button Macros that supplies a large list of macros that you can use for specifing paths (like $(SolutionDir) and $(Configuration)).

expample : $(SolutionDir)\lib1\$(Configuration)

You could build the solution now and no errors of not finding libraries should come up.

EDIT ,NB: if there is no source compiled in the library the build will be successfull but no library will be made, so you need some code in it. Otherwise the library will still not be found.

Now there's one more step to take. Your Libraries should supply header-files to use the libs but if you include them in your source the compiler cannot find them. You need to add additional include directories to your executable-projects properties. Go to the C/C++ option in the executable-projects properties and there you'll find the additional include directories and there you choose edit and supply the dirs containing the header-files you need.

expample : $(SolutionDir)\lib1

Now you're ready to go. By the way, try one library at a time so you go through the process a few times, learning and getting experienced with it.

Hope this will suffice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜