Cannot build libadjoint, conflict with PETSc C++-only build

Bug #1134511 reported by Timothée Lecomte
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
libadjoint
Fix Committed
Medium
Patrick Farrell

Bug Description

I am trying to build libadjoint to use on MacOS X Snow Leopard. I plan to use it with dolfin-adjoint. I have built dolfin and its dependencies using Dorsal, so I am trying to use Dorsal to build libadjoint and dolfin-adjoint too.

Libadjoint fails to build: the error appears when including a PETSc header, that complains that PETSc was compiled with --with-language=cxx, but it is now being used by a C compiler... In fact PETSc was built that way.

(I tried compiling libadjoint with a C++ compiler, using "CC=g++", but I only got a whole bunch of other errors because g++ seems to be stricter on casts in particular.)

Can you please help me build libadjoint ? Thanks !

The output is here:

Fetching libadjoint
Not checking SSL certificate for xmlrpc.launchpad.net
You have not informed bzr of your Launchpad ID, and you must do this to
write to Launchpad or access private data. See "bzr help launchpad-login".
Branched 409 revisions.
Building libadjoint
  CC src/adj_adjointer_routines.c
i686-apple-darwin10-gcc-4.2.1: -lstdc++: linker input file unused because linking not done
  CC src/adj_adjointer_visualisation.c
i686-apple-darwin10-gcc-4.2.1: -lstdc++: linker input file unused because linking not done
  CC src/adj_core.c
i686-apple-darwin10-gcc-4.2.1: -lstdc++: linker input file unused because linking not done
  CC src/adj_data_structures.c
i686-apple-darwin10-gcc-4.2.1: -lstdc++: linker input file unused because linking not done
  CC src/adj_debug.c
i686-apple-darwin10-gcc-4.2.1: -lstdc++: linker input file unused because linking not done
  CC src/adj_dictionary.c
i686-apple-darwin10-gcc-4.2.1: -lstdc++: linker input file unused because linking not done
  CC src/adj_error_handling.c
i686-apple-darwin10-gcc-4.2.1: -lstdc++: linker input file unused because linking not done
  CC src/adj_evaluation.c
i686-apple-darwin10-gcc-4.2.1: -lstdc++: linker input file unused because linking not done
  CC src/adj_petsc_data_structures.c
In file included from /Users/tlecomte/FEniCS-Dorsal-stable/include/petscis.h:7,
                 from /Users/tlecomte/FEniCS-Dorsal-stable/include/petscvec.h:9,
                 from /Users/tlecomte/FEniCS-Dorsal-stable/include/petscmat.h:6,
                 from /Users/tlecomte/FEniCS-Dorsal-stable/include/petscdm.h:6,
                 from /Users/tlecomte/FEniCS-Dorsal-stable/include/petscpc.h:6,
                 from /Users/tlecomte/FEniCS-Dorsal-stable/include/petscksp.h:6,
                 from /Users/tlecomte/FEniCS-Dorsal-stable/include/petscsnes.h:6,
                 from /Users/tlecomte/FEniCS-Dorsal-stable/include/petscts.h:7,
                 from /Users/tlecomte/FEniCS-Dorsal-stable/include/petsc.h:4,
                 from include/libadjoint/adj_petsc.h:14,
                 from include/libadjoint/adj_petsc_data_structures.h:14,
                 from src/adj_petsc_data_structures.c:1:
/Users/tlecomte/FEniCS-Dorsal-stable/include/petscsys.h:39:2: error: #error "PETSc configured with --with-clanguage=c++ and NOT --with-c-support - it can be used only with a C++ compiler"

Revision history for this message
Patrick Farrell (pefarrell) wrote :

Hi,

I think I fixed this in r410, just committed. Can you try it out and let me know if it works for you?

Regardless, libadjoint only has a soft dependency on PETSc (it's necessary only for the GST calculations, so if you don't intend to do any of those, you don't need it; just "unset PETSC_ARCH; unset PETSC_DIR". Either way, please let me know if your problem is fixed.

Cheerio,

Patrick

Changed in libadjoint:
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → Patrick Farrell (pefarrell)
Revision history for this message
Timothée Lecomte (timothee-lecomte-5) wrote :

Hi Patrick,

Thank you very much for your very fast answer !

I have just building r410 with "CC=g++", and I get other errors in adj_debug.c related to "double complex". I have replace a couple of expressions like "cabs((double complex) yGx - GTyx)" to "abs(yGx - GTyx)" when I saw that the variables are doubles, not complex, and then libadjoint successfully builds !

Here is the output (before fixing the errors related to double complex):
src/adj_debug.c: In function ‘int adj_test_block_action_transpose(adj_adjointer*, adj_block, adj_vector, adj_vector, int, double)’:
src/adj_debug.c:329: error: expected primary-expression before ‘double’
src/adj_debug.c:329: error: expected `)' before ‘double’
src/adj_debug.c:335: error: expected `)' before ‘}’ token
src/adj_debug.c:335: error: expected primary-expression before ‘}’ token
src/adj_debug.c:335: error: expected `;' before ‘}’ token
src/adj_debug.c: At global scope:
src/adj_debug.c:271: warning: unused parameter ‘tol’
src/adj_debug.c: In function ‘int adj_test_nonlinear_derivative_action_transpose(adj_adjointer*, adj_nonlinear_block_derivative, adj_vector, adj_vector, int, double)’:
src/adj_debug.c:404: error: expected primary-expression before ‘double’
src/adj_debug.c:404: error: expected `)' before ‘double’
src/adj_debug.c:410: error: expected `)' before ‘}’ token
src/adj_debug.c:410: error: expected primary-expression before ‘}’ token
src/adj_debug.c:410: error: expected `;' before ‘}’ token

May I suggest that the Makefile also prints a message to help future users find that they need to use a C++ compiler if they want the PETSc feature when the latter was built with C++ ?

Thank you again for your help !

Revision history for this message
Patrick Farrell (pefarrell) wrote :

Hi Timothy,

Sorry for the delay in replying, I'm at a conference this week.

I can't reproduce your double complex issue. double complex is perfectly valid C, so it should be perfectly valid C++; I have no idea why it wouldn't work.

I think that a) a user really wanting PETSc (it's an optional loose dependency) and b) only being able to compile petsc with the C++ compiler (for whatever reason) is pretty rare. Trapping that error is really hard, and I'm not sure it's worth it.

What OS are you on? Which version of g++? Perhaps I can try to reproduce your error. Alternatively, I'd be very happy to accept patches/merge requests for a modification to adj_debug.c that cleanly compiles with both C and C++ compilers.

Revision history for this message
Patrick Farrell (pefarrell) wrote :

Actually, I remembered I have ssh access to a Mac, and fixed it in r411.

Changed in libadjoint:
status: In Progress → Fix Committed
Revision history for this message
Timothée Lecomte (timothee-lecomte-5) wrote :

Thanks Patrick for your work on this. I have now tried again with r418 (still with CC="g++" make install). The build step works, but not the linking, unfortunately. Here is the output :

  CC src/adj_adjointer_routines.c
g++ -g -O0 -fPIC -I/Users/tlecomte/FEniCS-Dorsal-stable/include -I/Users/tlecomte/FEniCS-Dorsal-stable//include -DHAVE_SLEPC -I/Users/tlecomte/FEniCS-Dorsal-stable/include -I/Users/tlecomte/FEniCS-Dorsal-stable/include -I/usr/local/include -I/usr/local/Cellar/mpich2/1.5/include -DHAVE_PETSC -Iinclude/ -Wall -Wextra -Wunused-parameter -Wunsafe-loop-optimizations -Wno-write-strings -Wpointer-arith -ggdb3 -fstack-protector-all -fno-leading-underscore -c -o obj/adj_adjointer_routines.o src/adj_adjointer_routines.c

...a bunch of other successful CC...

  SED include/libadjoint/adj_constants_f.h
  SED include/libadjoint/adj_error_handling_f.h
  FC src/adj_fortran.F90
  C++ src/revolve.cpp
  C++ src/revolve_c.cpp
  AR lib/libadjoint.a
  LD lib/libadjoint.dylib
Undefined symbols:
  "_Z9EPSCreateiPP6_p_EPS", referenced from:
      _Z15adj_compute_gstP13adj_adjointer12adj_variableP10adj_matrixS1_S3_iP7adj_gstPi in adj_predictability.o
  "_adj_variable_equal", referenced from:
      ___libadjoint_MOD_adj_variable_equal in adj_fortran.o
     (maybe you meant: ___libadjoint_MOD_adj_variable_equal)
  "_adj_variable_get_ndepending_timesteps", referenced from:
      ___libadjoint_MOD_adj_variable_get_ndepending_timesteps in adj_fortran.o
     (maybe you meant: ___libadjoint_MOD_adj_variable_get_ndepending_timesteps)
  "_adj_adjointer_to_html", referenced from:
      ___libadjoint_MOD_adj_adjointer_to_html in adj_fortran.o
     (maybe you meant: ___libadjoint_MOD_adj_adjointer_to_html)
  "_Z7MatAXPYP6_p_MatdS0_12MatStructure", referenced from:
      _Z19petsc_mat_axpy_procP10adj_matrixdS_ in adj_petsc_data_structures.o
  "_Z14MatAssemblyEndP6_p_Mat15MatAssemblyType", referenced from:
      _Z16petsc_solve_proc12adj_variable10adj_matrix10adj_vectorPS1_ in adj_petsc_data_structures.o
  "_adj_create_term", referenced from:
      ___libadjoint_MOD_adj_create_term in adj_fortran.o
     (maybe you meant: ___libadjoint_MOD_adj_create_term)

... a whole lot of other undefined symbols...

ld: symbol(s) not found
collect2: error: ld returned 1 exit status
make: *** [lib/libadjoint.dylib] Error 1

For reference, here is the output of 'g++ --version':
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)

And of 'uname -a':
10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64

If you think you can do something easily to finish the build, then ok, but given your findings about python bindings in #1135519, I'm not sure it's worth the effort...

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.