Monday, June 13, 2016

compiling C code in Visual Studio 2008, 2010,

compiling C code in Visual Studio 2008, 2010,

  1. Compiling C code in Visual Studio 2012
  2. direct note from the page is copied here. this setup is project level.

    Before you run your project, you’ll need to tell Visual Studio that you’ve written C code; otherwise, Visual Studio will assume you’ve written C++ code and things will go wonky. Click Project → Properties. Expand Configuration Properties and then expand C/C++. Click on Advanced. Change Compile As to Compile as C Code (/TC) and click OK.

    Key Note: in project shortcut->properties->Configuration Properties->C/C++->Advanced section: change Compile As to Compile As C Code(/TC) and click OK.

  3. Create C Program with Static Library using Visual Studio 2012

    in client project, first create a empty windows console project.
    step 1: Specify static library file(*.lib). Select MyApps1, right click and select properties. Under Common Properties, select Framework and References. Click "Add New Reference"

    step 2: Specify the path to include header files. On the properties page, under Configuration Properties >> C/C++ expand the list in C/C++ and select "General" as shown below. then two sub-steps
    step 2-a: For first line "Additional Include Directories", click the arrow and select edit. The following dialog box shows:
    step 2-b: Click the "New Line" icon and click on the button "...". Now you need to navigate to the static library folder. Do not select the folder "MyMathLib" under Projects, drill one level down and select the folder "MyMathLib" - this is project folder, not solution folder. Highlight the folder and click select folder. this is used to specify the include file directory

  4. Walkthrough: Creating and Using a Static Library (C++)

    after create a empty console project, next it is to configure the settings.
    step 1.Before we can use the math routines in the static library, we must reference it.
    To do this, open the shortcut menu for the MyExecRefsLib project in Solution Explorer, and then choose References. In the MyExecRefsLib Property Pages dialog box, expand the Common Properties node, select Framework and References, and then choose the Add New Reference button. This is another way to start the reference tab.
    For more information about the References dialog box, see Adding references in Visual C++ projects.
    The Add Reference dialog box lists the libraries that you can reference. The Projects tab lists the projects in the current solution and any libraries that they contain. On the Projects tab, select the MathFuncsLib check box, and then choose the OK button.

    step 2.To reference the header file(MathFuncsLib.h), we must modify the included directories path.
    In the Property Pages dialog box for MyExecRefsLib, expand the Configuration Properties node, expand the C/C++ node, and then select General. Next to Additional Include Directories, specify the path of the MathFuncsLib directory or browse for it.
    To browse for the directory path, open the property value drop-down list, and then choose Edit. In the Additional Include Directories dialog box, in the text box, select a blank line and then choose the ellipsis button (…) at the end of the line. In the Select Directory dialog box, select the MathFuncsLib directory and then choose Select Folder button to save your selection and close the dialog box. In the Additional Include Directories dialog box, choose the OK button, and then in the Property Pages dialog box, choose the OK button to save your changes to the project.

  5. The Basics of Creating a Static Library Using Visual C++

    Firstly this is a C++ project.

    Note that the extern "C" makes the function callable by C and by other languages as well. The disadvantage of extern "C" is that it prevents use of classes and other C++ features with any functions exposed for use by callers of the static library.

    After create the static library, we need to write a client project to consume it. more importantly we need to configure the project well.

    step 1. configure include file path. set up on test project level.
    Go to the Solution Explorer and right-click on the test project, then select "Properties". In the left side, under "Configuration properties" expand the "C/C++" node, then select "General". In the top-right is "Configuration"; change it to "All Configurations". Then in "Additional Include Directories" add the directory of the static library project where the static library's header (StaticLibrarySample.h) is at.

    step 2A. configure library reference::we need to specify the library to be used::
    In the project properties, and with the configuration set for All Configurations, go to the "Input" node of the "Linker" properties. In the "Additional Dependencies" add the name of the static library; just the filename and extension, but not the directory. The properties window will look something like:
    no need to add "$(AdditionalDependencies)" as in the example. otherwise you will get error.

    step 2B.configure library reference::we need to specify the directory of the library::
    That is done in the project properties, but this time we will specify different directories for each configuration. So with the configuration set for "Active(Debug)", go to the "General" node of the "Linker" properties. Specify the directory where the Debug configuraton of the library is at. The property page will look something like:

    Step 3. add header file into test project source file.
    Then in the test program's cpp file, after the include for "stdafx.h", add an #include for "StaticLibrarySample.h".

    step 4. One more thing worth doing is to ensure that the solution knows that the test project depends on the static library.
    Go to the Solution Explorer again but right-click on the Solution then choose Properties. Then in the left side click on "Project Dependencies" under the "Common Properties" node. Ensure that the test project has the checkbox checked for the static library. That property page looks like:

  6. Understanding “extern” keyword in C

    good summary of keyword "extern".

  7. Linker Tools Error LNK1104

    good,authoritive definitions.

  8. Why does fatal error “LNK1104: cannot open file 'C:\Program.obj'” occur when I compile a C++ project in Visual Studio?

    This particular issue is caused by specifying a dependency to a lib file that had spaces in its path. The path needs to be surrounded by quotes for the project to compile correctly.
    On the Configuration Properties -> Linker -> Input tab of the project’s properties, there is an Additional Dependencies property. This issue was fixed by changing this property from:
    C:\Program Files\sofware sdk\lib\library.lib
    " C:\Program Files\sofware sdk\lib\library.lib"

  9. compile C program right in the Visual Studio 2012?
  10. Adding references in Visual C++ projects

    this gives more details on reference page.

  11. compiling C code in Visual Studio 2008
  12. Using Microsoft Visual Studio for Simple C Programs
  13. Walkthrough: Compiling a C Program
  14. How Do I Compile and Link C Code, Not C++?
  15. Visual Studio 2010: Property Sheets and C++ Directories
  16. Changing Visual Studio's default build output path
  17. VC++ Directories Property Page for Visual C++ 2015

    Specifies the directories that you want Visual Studio to use to build a project. To access this property page, in Solution Explorer, open the shortcut menu for the project and choose Properties, and then in the left pane of the Property Pages dialog box, expand Configuration Properties and select VC++ Directories.

    When you use Visual Studio to create a project, it inherits certain directories. Many of these are given as macros. To examine the current value of a macro, in the right pane of the VC++ Directories page, select a row—for example, Include Directories—choose the down-arrow button on the right, choose Edit, and then in the dialog box that appears, choose the Macros button. For more information, see these blog posts: VC++ Directories, Inherited Properties and Property Sheets, and Visual Studio 2010 C++ Project Upgrade Guide.

No comments:

Post a Comment