0

I have a simple C++ library which uses a short autoconf, automake and libtool to build a shared library object.

Now I want to be able to dynamically compile new code at run-time in my program, by:

  • Output code to a temporary file (say /tmp/code.cc)
  • Compile to a library
  • Dynamically load code.so into my code

I want to find the commands I need to run to do this. I can see the commands used by running 'make -n', but I really don't want to try using awk to search and replace bits of these commands!

Chris Jefferson
  • 7,225
  • 11
  • 43
  • 66

1 Answers1

2

This problem can be decomposed into following sub-problems:

  • Determine how you have compiled the program itself (compiler and / or flags should not be mixed, especially not in case of the C++ language). You do this by exporting CC, CXX, CFLAGS, CXXFLAGS and CPPFLAGS to the config.h file using AC_DEFINE autoconf macro in configure.ac. Or you may use AC_SUBST and your custom header.h.in to store those variables in a file of your choice.

  • Then you call compiler CC giving him CPPFLAGS and CFLAGS or CXX with CPPFLAGS and CXXFLAGS. However, if you want to load those files by your program, you may consider using the Libtool library called libltdl, which implements plug-in stuff in a cross-platform way.

  • You may consider using libtool script as a cross-platform compilation wrapper, but you will have to study it a bit since it is somehow arcane - there are compilation, linking and "installation" phases, but they are handled in a cross-platform way and if you pass the -sharee argument, some additional flags you need (-fPIC and possibly others) will be passed automagically.

bubla
  • 963
  • 9
  • 10
  • Your reply has convinced me that this problem is hard enough I'm going to tackle the problem in a different way -- but I believe your answer is correct if anyone else is ever brave enough to do so! – Chris Jefferson Mar 03 '15 at 13:41