<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6618.4">
<TITLE>Mixing C and Fortran in Visual Studio with Intel Visual Fortran</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">I'm having trouble using CMake in a project with mixed Fortran and C code </FONT>

<BR><FONT SIZE=2 FACE="Arial">and I'm hoping someone here can help.&nbsp; I am using Visual Studio 2005 and </FONT>

<BR><FONT SIZE=2 FACE="Arial">Intel Visual Fortran 9.1.&nbsp; Sorry for the length of this post.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">1) The test for the Fortran compiler is failing indicating a broken compiler.&nbsp;&nbsp; </FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp;It breaks during the link stage with the following error:</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Microsoft (R) Visual Studio Version 8.0.50727.42.</FONT>

<BR><FONT SIZE=2 FACE="Arial">Copyright (C) Microsoft Corp 1984-2005. All rights reserved.</FONT>

<BR><FONT SIZE=2 FACE="Arial">------ Build started: Project: cmTryCompileExec, Configuration: Debug Win32 ------</FONT>

<BR><FONT SIZE=2 FACE="Arial">Building Fortran object testFortranCompiler.obj</FONT>

<BR><FONT SIZE=2 FACE="Arial">Linking Fortran target cmTryCompileExec.exe</FONT>

<BR><FONT SIZE=2 FACE="Arial">Fatal error cannot open &quot;ifconsol&quot;</FONT>

<BR><FONT SIZE=2 FACE="Arial">ifort: error: problem during multi-file optimization compilation (code 1)</FONT>

<BR><FONT SIZE=2 FACE="Arial">Project : error PRJ0019: A tool returned an error code from &quot;Linking Fortran tar</FONT>

<BR><FONT SIZE=2 FACE="Arial">get cmTryCompileExec.exe&quot;</FONT>

<BR><FONT SIZE=2 FACE="Arial">Build log was saved at ...</FONT>

<BR><FONT SIZE=2 FACE="Arial">\cmTryCompileExec.dir\Debug\BuildLog.htm&quot;</FONT>

<BR><FONT SIZE=2 FACE="Arial">cmTryCompileExec - 2 error(s), 0 warning(s)</FONT>

<BR><FONT SIZE=2 FACE="Arial">========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Searching the net revealed that this problem is caused by a missing or </FONT>

<BR><FONT SIZE=2 FACE="Arial">invalid &quot;LIB&quot; environment variable.&nbsp;&nbsp; The LIB environment variable points </FONT>

<BR><FONT SIZE=2 FACE="Arial">to the location of the Intel libraries.&nbsp;&nbsp; LIB is set in my environment and </FONT>

<BR><FONT SIZE=2 FACE="Arial">the link does in fact work outside of cmake generated projects.&nbsp; Is it</FONT>

<BR><FONT SIZE=2 FACE="Arial">possible that cmake is somehow resetting this environment variable?</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Even though the generator complains the Fortran compiler is broken I </FONT>

<BR><FONT SIZE=2 FACE="Arial">can still generate projects using CMakeSetup.exe which leads to </FONT>

<BR><FONT SIZE=2 FACE="Arial">my next set of problems.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">2) The generated project is trying to compile my .c files with the fortran </FONT>

<BR><FONT SIZE=2 FACE="Arial">compiler.&nbsp; For example:</FONT>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=1 FACE="Courier New">Building Fortran object lock.obj</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=1 FACE="Courier New">Intel(R) Fortran Compiler for 32-bit applications, Version 9.1&nbsp;&nbsp;&nbsp; Build 20060323Z Package ID: W_FC_P_9.1.023 </FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=1 FACE="Courier New">Copyright (C) 1985-2006 Intel Corporation.&nbsp; All rights reserved.</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=1 FACE="Courier New">ifort: Command line warning: unrecognized source type '..\lock.c'; object file assumed</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=1 FACE="Courier New">ifort: Command line warning: no action performed for specified object file(s)</FONT></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN><SPAN LANG="en-us"></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">How do I specify that the .c file should get compiled with cl.exe?</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">3) Most of my Fortran files get built but it puts the .obj files in the </FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&quot;wrong&quot; directory.&nbsp;&nbsp; It is creating them in ${CMAKE_CURRENT_BINARY_DIR} </FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">instead of the ${CMAKE_CURRENT_BINARY_DIR}\&lt;project&gt;.dir\Debug directory.</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">How do I specify that the object files go in the directory with the .c objects?</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Thanks for any help,</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Kevin</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">Here is the CMakeLists.txt file I'm using:</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"># =========</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">ENABLE_LANGUAGE(Fortran)</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">#</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"># source files</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">#</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">SET(FORTRAN_SOURCES</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&nbsp; &lt;list of .f files&gt;</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">)</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">SET(C_SOURCES</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp; &lt;list of .c files&gt;</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">)</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">SET(SOURCE_FILES ${FORTRAN_SOURCES} ${C_SOURCES})</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">#</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"># add the fortran source files to the Source Files folder</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">#</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">SOURCE_GROUP(&quot;Source Files&quot; REGULAR_EXPRESSION &quot;\\.(F|f)&quot; FILES ${SOURCE_FILES})</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">#</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"># make the header file list</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">#</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">FILE(GLOB C_HEADER_FILES ${Project_SOURCE_DIR}/lib/include/sio/*.h)</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">FILE(GLOB FORTRAN_HEADER_FILES ${Project_SOURCE_DIR}/lib/include/sio/*.inc)</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">SET(HEADER_FILES ${C_HEADER_FILES} ${FORTRAN_HEADER_FILES})</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">SOURCE_GROUP(&quot;Header Files&quot; REGULAR_EXPRESSION &quot;\\.(H|h|inc)&quot; FILES ${HEADER_FILES})</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">SET(SOURCE_FILES ${SOURCE_FILES} ${HEADER_FILES})</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">#</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"># library name</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">#</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">ADD_LIBRARY(libmixed SHARED ${SOURCE_FILES})</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">IF (WIN32)</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp; SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /fpp ) </FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp; SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /traceback)</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp; SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /check:bounds)</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp; SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /threads)</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp; SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /MDd)&nbsp;&nbsp; </FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp; SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /extfor:F)</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp; SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /Qvc8)</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">&nbsp;&nbsp; SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /assume:underscore)</FONT></SPAN>

<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial">ENDIF (WIN32)</FONT></SPAN>
</P>

<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Arial"># =========</FONT></SPAN>
</P>

</BODY>
</HTML>