# Undefined symbol with TSpectrum

**URL:** <https://root-forum.cern.ch/t/undefined-symbol-with-tspectrum/24109>\
**Category:** ROOT\
**Created:** [March 16, 2017, 5:23pm UTC](https://root-forum.cern.ch/t/undefined-symbol-with-tspectrum/24109 "2017-03-16T17:23:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e495f1/32.png) [@jasot](https://root-forum.cern.ch/u/jasot)\
**Post date:** [March 16, 2017, 5:23pm UTC](https://root-forum.cern.ch/t/undefined-symbol-with-tspectrum/24109/1 "2017-03-16T17:23:18Z")

</div>

Hello,

I have a problem when I try to use the TSpectrum class.

I’m using cmake to compile a binary from a code that works fine, but if I declare a variable TSpectrum, I get the following error when I run the macro (cmake and make gives no errors, it compiles fine):

`/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/5.34.34/x86_64-cc7-gcc48-opt/root/bin/root.exe: symbol lookup error: ~/WA105_LightSoft/build/lib/libLightSoft.so: undefined symbol: _ZN9TSpectrumC1Eif`

And if I do filt:

```auto
 bash-4.2$ c++filt -n _ZN9TSpectrumC1Eif
TSpectrum::TSpectrum(int, float)

```

I think it may be cased by a bad definition of the libraries, but then I don’t understand why I can use all the other ROOT classes without problems (TH, TF…). I don’t know if it is a cmake or ROOT problem…

I attach my CMakeLists.txt

Any help is welcome!

Best regards,  
J

[CMakeLists.txt](https://root-forum.cern.ch/uploads/default/original/2X/0/0dfa839bb8d9265851a9a0e59809eff9ac3cef68.txt) (1.8 KB)

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [March 17, 2017, 3:53pm UTC](https://root-forum.cern.ch/t/undefined-symbol-with-tspectrum/24109/2 "2017-03-17T15:53:41Z")

</div>

Hi,

the library does contain the symbol

```auto
nm -C /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/5.34.34/x86_64-cc7-gcc48-opt/root/lib/libSpectrum.so |grep "TSpectrum::TSpectrum("
0000000000078e20 T TSpectrum::TSpectrum(int, float)
0000000000078bd0 T TSpectrum::TSpectrum()
0000000000078e20 T TSpectrum::TSpectrum(int, float)
0000000000078bd0 T TSpectrum::TSpectrum()

```

I think it just needs to be linked and LD\_LIBRARY\_PATH set correctly.

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![jasot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e495f1/32.png) [@jasot](https://root-forum.cern.ch/u/jasot)\
**Post date:** [March 21, 2017, 11:23am UTC](https://root-forum.cern.ch/t/undefined-symbol-with-tspectrum/24109/3 "2017-03-21T11:23:20Z")

</div>

Thanks for your answer dpiparo, but do you know how can I do this?

In the FindROOT.cmake that I’m using, I found:

```auto
    ADD_CUSTOM_COMMAND(OUTPUT ${OUTFILES}
       COMMAND LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR} ROOTSYS=${ROOTSYS} ${ROOT_CINT_EXECUTABLE}
       ARGS -f ${OUTFILE} -c -DHAVE_CONFIG_H ${INCLUDE_DIRS} ${INFILES} ${LINKDEF_FILE} DEPENDS ${INFILES} ${LINKDEF_FILE})

```

And later:

```auto
  SET(LD_LIBRARY_PATH ${LD_LIBRARY_PATH} ${ROOT_LIBRARY_DIR})

```

I’m new using this, and I am a bit lost, any help is welcome.

[FindROOT.cmake.txt](https://root-forum.cern.ch/uploads/default/original/2X/2/29e8cafef94807ebd4c2701be119c56ac61c6d34.txt) (9.4 KB)

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [March 21, 2017, 2:03pm UTC](https://root-forum.cern.ch/t/undefined-symbol-with-tspectrum/24109/4 "2017-03-21T14:03:15Z")

</div>

Hi,

You’ll need to link with `libSpectrum` (CMake calls it `Spectrum`); check the CMake doc on how to add a library to the target of your library / binary. I believe it’s `target_link_libraries(LightSoft Spectrum)`.

Cheers, Axel.

---

<div class="post-metadata">

**Author:** ![jasot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e495f1/32.png) [@jasot](https://root-forum.cern.ch/u/jasot)\
**Post date:** [March 21, 2017, 2:38pm UTC](https://root-forum.cern.ch/t/undefined-symbol-with-tspectrum/24109/5 "2017-03-21T14:38:05Z")

</div>

Thank you, Axel. Finally I got it, I just added the line target\_link\_libraries(LightSoft Spectrum), and it works.

Best regards,  
José

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [March 21, 2017, 2:52pm UTC](https://root-forum.cern.ch/t/undefined-symbol-with-tspectrum/24109/6 "2017-03-21T14:52:33Z")

</div>

Good! I updated my post to remove the comma - thanks.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 4, 2017, 2:52pm UTC](https://root-forum.cern.ch/t/undefined-symbol-with-tspectrum/24109/7 "2017-04-04T14:52:44Z")

</div>

Closed on April 4, 2017, 2:52pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
