I am using visual Studio 2010 for compiling a bunch of source File. I am new to it and I wonder how the object files are linked during compilation. Like in Linux we have make file and rules. Does this suppport makefile? If not how can I compile and set flag during compilation.
You can use makefiles and other command-line tools to build using Visual C++ but more typically you handle this by using the GUI to set properties at the Project and File level - start here for info on this.
The Project/File properties adjust the command-line options passed to the compiler and linker for each compilation unit. You can view the actual command line that's used in the GUI too.
Related
I have a basic question that I cannot find the answer to even after searching the web many times.
Is it possible to compile a Fortran program by IFORT that uses (as dependencies) object files (i.e. .lib) that were compiled by Microsoft Visual Studio C?
Yes, it is possible, and is even rather easy. You have several options for how to do this:
Add the MSVC library project to your Fortran Visual Studio solution and then use Project > Dependencies to add the C project as a dependent of your Fortran project *does not work if the C project creates a DLL)
Add the .lib from the C project to the Fortran project as if it were a source file
Name the C .lib in the Linker > Input > Additional Dependencies project property.
I generally recommend the first choice, as it means you don't have to fuss with different settings for Debug and Release projects. You do need to make sure that the C library is built to specify the same run-time library type (Debug vs. Nondebug, DLL vs. Static) as the Fortran project. This is in the Code Generation property page for C.
There is a worked example "Fortran Calls C" in the Intel Parallel Studio XE for Windows Sample Bundle.
You'll also need to understand how to call a C procedure from Fortran and ensure that the C arguments have compatible Fortran types. It works best if you make use of the Fortran standard's "C interoperability" features.
Please don't answer this as a "How do I cross-compile on Linux for Windows" question, I solved that part. I need some specific instruction on configuring Netbeans. Thank you.
I'm developing a set of C functions that I want to distribute as a .dll on Windows, and a .so on Linux. (This is going to be used from java as a JNI library, but that's irrelevant to the question).
Development environment is Netbeans 8.2.
I have gcc and mingw installed, and compiling my source code for both targets works.
However, I want to create NetBeans configurations "Linux-Release" and "Windows-Release", with Linux-Release using gcc to create the .so file, and Windows-Release using x86_64-w64-mingw32-gcc. So I created a Mingw tools collection that refers to the mingw versions of the C compiler:
In my project properties, I created a Windows_Debug configuration, and told it to use the Mingw tool collection:
I can use this configuration to get a working Dll. However, the output file will be put into the dist/Windows_Debug/Mingw-Linux directory (not dist/Windows_Debug/Mingw-Windows as I'd like), and it's put there with a .so extension, not .dll. I can load this file on Windows when I rename it to .dll, but this will horribly confuse anyone I want to collaborate with.
Naively messing with the CND_DLIB_EXT macro in the generated Makefiles doesn't help at all, they just get overwritten.
I guess I have to either tell Netbeans that the Mingw Tool Collection compiles to Windows, or that the Windows_* configurations compile to Windows, so Netbeans sets the correct values for CND_* and the default output Macro
${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libSMAQSJni.${CND_DLIB_EXT}
in the linker part of Project Properties works again. (Of course, as a workaround, I could just remove the variables from the macro, and replace them with appropriate constants, but I want to do this "right". I haven't found a way to tell Netbeans "this compiles to Windows" anywhere though, neither in the GUI nor in any of the config files. So, how do I do this?
I have a program in C. I need to use a SQLite library to read data from a database.
When I include sqlite3.h to my source file I get unresolved symbol errors on sqlite3 functions.
If I add lib file as library I don't get any error but program requires sqlite3.dll to run.
I already tried to play with compiler settings but nothing changed.
SQLite is written in C and my program is also C. Why do I need a DLL file to use SQLite?
How can I remove the DLL dependency.
I'm using MCVS2015 community edition IDE.
The recommended way of compiling SQLite is to download the amalgamation source code file (sqlite3.c), and to add it to your project.
I was trying with VS2012 to do following:
File->New Project->Win 32 Console application.
Go to properties C/C++->advanced and set Compile as C Code (/TC)
Rename source files extension cpp->c (not sure it is needed)
But project is compiled like C++ anyway.
What else should be done to make project compile as C?
From the MSDN,
By default, the Visual C++ compiler treats all files that end in .c as
C source code, and all files that end in .cpp as C++ source code. To
force the compiler to treat all files as C regardless of file name
extension, use the /Tc compiler option.
Also, Compiling with ANSI C in Visual Studio
It is compiling as C.
Not as C99 or C11 or C-plus-support-for-APIs-from-other-OSes.
Just plain ISO-standard-compliant C89/C90. Which is what the C compiler shipped with VS2012 supports.
I started programming in C and I have Visual Studio 2012.
I Write my program in Win32 ConsoleApplication and when I look in the Debug in my project there is an EXE file, and it work, but when i try to take it and run it from other computer that not runs Visual Studio it not working.
what i can do for it to work?
Thanks, Tomas.
go to the project properties and then: C/C++ -> Code Generation -> Runtime Library and then select the MT or MTD option depending in which configuration you are (for release MT and debug MTD)
The standard C functions like printf, fopen and strlen are delivered by the compiler vendor in a precompiled library and DLL. The default setting in projects is to not link all the standard functions directly into your program but keep them in an extra DLL and let your compiled program just use that DLL. On your machine with Visual Studio that DLL is present. On your other machine that DLL is not present.
There are two ways to solve that:
Look at the C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist and copy the DLLs you need to the target machine.
You can go the project settings "C/C++"/"Code Generation" and change the setting "Runtime Library" to a value without "DLL" in its name (/MT and /MTD). Then the compiler directly links all the standard C functions into your program and you can just copy your program to the other machine.
The reason Microsoft prefers the DLL is that with the DLL you can have multiple small programs in a folder each using the same DLL. If linking statically you end up with multiple bigger programs where each program has built in the same functions.