How to run a single .c file in a .lib project in visual C++ Express?
I tried right click that .c
file,but there is only a "Compile" option.
How to ru开发者_如何学Gon the main
function inside it?
You need to include that .c file in a project that will be an Executable (.exe) instead of a .lib - you can't run a .lib.
You shouldnt have a main function in a library. What I usually do when creating a library is to create two projects, 1 for the library itself and 1 for a simple app that will be used to test the library.
Main functions are allowed for Applications and not libs, dlls etc. Try creating an application project and add your files to it. In that also, you can execute only the whole project, you can't get the execute option by doing a right click on the .c file.
I guess what you need is a Console Application. Please check VC help for further details.
You need two projects contained within one solution. I'm assuming you are build a non-mfc win32 project.
1) Create a new library project. This is done by creating a win32 project and selecting either static or dll library. You've probably already have done this.
2) Note that you have a solution open as well, MSDev created a solution for you. Solutions group together many different projects.
4) Right click the solution and select add new win32 console project. Create a win32 executable project. Add your main.c to it - it easier if you create an empty executable project . . . you don't want a project that contains to main functions . . you might have to delete the generated source file - or you can use it as a template.
5) Right click on executable project and select 'make this the startup project'.
6) Right click on the project again and select dependencies. Make sure that the library project is checked as a dependency. This will ensure that it is built first. Confirm by viewing build order.
7) Do a trial build and check the results in the debug directory of the solution . . . you should find both dll and exe in the same place.
That should work . . .
You can continue to add different kinds of projects to that root solution. If you exit msdev, you can rename your solution to something more descriptive
精彩评论