[CMake] making executible in mixed C/fortran project

luxInteg lux-integ at btconnect.com
Fri Nov 12 11:37:31 EST 2010


On Friday 12 November 2010 13:17:50 Michael Hertling wrote:
> On 11/12/2010 02:46 PM, luxInteg wrote:
> > Greetings,
> > 
> > I am learning cmake
> > 
> > I am building an executable  which needs to   first compile a C program 
> > and then recompiling the object file   with another file in fortran.
> > 
> > 
> > Here is  an excerpt from a unix makefile I am attempt to port to cmake as
> > part of my cmake turotial.
> > 
> > fileC.o: fileC.c
> > 
> > 	$(C) -DDINT -c fileC.c
> > 
> > fileD:  fileD.f fileC.o ../lib/libF.a
> > 
> > 	$(F77) $(F77FLAGS) -o fileD fileD.f fileC.o    ../lib/libF.a $(F77LIB)
> > 
> > I  think I have learnt enough cmake to do most of the above  EXCEPT I am
> > unsure how on compile an object file  (in this case  fileC.o
> > with a fortran compiler (if I have translated the makefile correctly)
> > 
> >  Does one  rename   the file or whatever?
> > 
> > Guidance on how to do this would be appreciated
> 
> You might try
> 
> ADD_LIBRARY(C STATIC fileC.c)
> 
> in junction with
> 
> TARGET_LINK_LIBRARIES(fileD C ...)

----------------
It would not go in the loop 

add_executable(fileD
fileD.f 
ADD_LIBRARY(fileC STATIC fileC.c )
${fileC}  )


so I tried  it outside like so:-

SET_SOURCE_FILES_PROPERTIES( fileC.c  PROPERTIES  COMPILE_DEFINITIONS DINT )
ADD_LIBRARY(fileC STATIC fileC.c )
add_executable(fileD
fileD.f 
${fileC}  )

target_link_libraries(fileD   $(F77LIB) )


-----------but  make ends like so:-
CMakeFiles/filedD.dir/filedD.f.o: In function `MAIN__':
filedD.f:(.text+0x2f9): undefined reference to `Ddefaults_'
filedD.f:(.text+0x32b): undefined reference to `Dorder_'
filedD.f:(.text+0x33a): undefined reference to `Dinfo_'
collect2: ld returned 1 exit status

-------------------

oher suggestions welcomed
> since you shouldn't directly refer to object files with CMake.
> 



More information about the CMake mailing list