Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial cmake support #36

Merged
merged 1 commit into from
Feb 22, 2016
Merged

initial cmake support #36

merged 1 commit into from
Feb 22, 2016

Conversation

nesteruk
Copy link
Contributor

This is an attempt to add initial CMake support to QuantLib so it can be compiled with CMake and opened with tools like CLion.

I have done the following:

  • Created a CMakeLists.txt file at each suitable location
  • Made a few choices regarding what gets built and how. For example, QuantLib is built as a shared (dynamic) library called quantlib.
  • Each example has its own CMakeLists.txt
  • Tests exclude the benchmarks file since I found no references to it in the VS .proj files. Maybe I didn't look hard enough.

As it stands, all parts of the arrangement compile and link successfully, but I cannot get the tests to work, probably due to my lack of experience with Boost.Test. Your assistance in this matter is appreciated.

@lballabio lballabio added this to the 1.8 release milestone Jan 14, 2016
@lballabio lballabio merged commit 64659cc into lballabio:master Feb 22, 2016
lballabio added a commit that referenced this pull request Feb 22, 2016
@lballabio
Copy link
Owner

I've merged the PR to master. I've made a couple of changes, so you might check that the thing still works for you (all the targets compile and link on my side, though, so I shouldn't have broken anything):

  • I have renamed the targets so that the names match what is currently built (so for instance it's libQuantLib.so instead of libquantlibso); see b2370d2.
  • on Linux, the test suite might need to be compiled with -DBOOST_TEST_DYN_LINK if Boost.Test was compiled as a static library. I've added an option for that, but since it's my first steps with CMake, I'd appreciate you having a look at it. The relevant commit is 6d71313.

As for the test suite: once I managed to build it *see above), I could also run it by launching the test-suite/quantlib-test-suite binary directly (I don't know what the CMake way to do it would be). It was about three times slower than usual—maybe due to missing optimization flags in the default compilation options?—but it ran successfully. What happened on your machine? And what was the operating system and compiler?

@nesteruk
Copy link
Contributor Author

I am building on Ubuntu/GCC. The exact issue I'm getting when building tests is as follows:

[100%] Linking CXX executable quantlib-test-suite
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
make[2]: *** [test-suite/quantlib-test-suite] Error 1
make[1]: *** [test-suite/CMakeFiles/quantlib-test-suite.dir/all] Error 2
make: *** [all] Error 2

@lballabio
Copy link
Owner

Ok, that's the same issue I had. If you check out my master and run the thing with the USE_BOOST_DYNAMIC_LIBRARIES option set to ON, it should build correctly.

(I wonder if this should be the default. It probably should on Linux, but I'm not sure how Boost is compiled on Windows. What compiler does cmake use there? Do you have a Windows box you can try this on?)

@zyv
Copy link

zyv commented Mar 7, 2016

Just a comment:

If I were you, I would create a single CMakeLists.txt for the Examples and put the stuff required for all of the examples in there. Of course, having one CMakeLists.txt per example is not anywhere nearly as bad as having e.g. a recursive make-based build system, because CMake will preprocess them all anyways.

However, I think that the argument of having too granular of a division makes it more difficult to maintain such a build system still stands. For sweeping changes, it would be much easier to edit one CMakeLists.txt for all examples, instead of going through each and every of the individual ones.

0.02 €

@pazzo83
Copy link

pazzo83 commented Mar 16, 2016

I have tried this method, and am running into some major issues. My build fails almost immediately with this error:

/QuantLib-1.7.1/ql/math/statistics/incrementalstatistics.cpp:32:23: error: no member named 'accumulators' in namespace 'boost'
        return boost::accumulators::extract_result<

This creates a cascade of errors.
As you can see from the file path, I am trying to do this with QuantLib-1.7.1

I had to add this to my main CMakeLists.txt:

find_package(Boost 1.56.0 COMPONENTS system filesystem REQUIRED)

if(Boost_FOUND)

    message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
    message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
    message(STATUS "Boost_VERSION: ${Boost_VERSION}")

    include_directories(${Boost_INCLUDE_DIRS})

endif()

Any suggestions?

Thanks!

@lballabio
Copy link
Owner

You're right, the find_package directive is needed. We probably didn't realize it because we already had Boost in the default include path.

Thanks for the heads-up. I've added the change to the repository. Let me know if it works for you.

@pazzo83
Copy link

pazzo83 commented Mar 17, 2016

works perfectly now!! (I just cloned the QuantLib repo and ran stuff from there). Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants