Author Topic: Undefined reference (SOLVED)  (Read 13042 times)

Offline jury

  • Multiple posting newcomer
  • *
  • Posts: 18
Undefined reference (SOLVED)
« on: May 07, 2021, 08:45:21 pm »
I have created Code::Blocks project from cmake (with -G "CodeBlocks - Unix Makefiles")
It compiles, but when linking I get undefined reference. Where do I add libraries for this project?
When searching for help I found this:
https://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_My_build_fails_with_multiple_undefined_reference_errors.3F
saying "Most of the time it is because the required library is not linked with your project. Go to Project->Build options...->Linker settings (tab) and add the required library or libraries"
But I do not have any Linker settings tab there. All I have is "Pre/post build steps", "Custom variables" and "Make"commands. I think I have went through all the possible menu entries, but I can not find any project linker settings.
What am I missing?

(yes, I have seen the same title topic from yesterday, but the advice there is exactly the same as in the link above: go to project -> build options and then linker settings tab)

Code::Blocks 20.3, PCLinuxOS
This project compiles and builds fine in command line.
« Last Edit: May 15, 2021, 04:13:01 pm by jury »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7576
    • My Best Post
Re: Undefined reference
« Reply #1 on: May 07, 2021, 09:44:46 pm »
You are using an CB custom makefile project because of your selection of "CodeBlocks - Unix Makefiles"; therefore you need to edit the makefile to change the build settings used by the makefile!

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Undefined reference
« Reply #2 on: May 07, 2021, 09:45:28 pm »
If you create a project from cmake, then this project is a so called "makefile project". With this type of project the codeblocks build process is circumvented and the cmake build process is used. For this all Settings in the Build options are ignored, because the cmake file is the build reference. If you have to add a library or source file ecc, or anything related to the build process, you have to modify your (c)make file

So you probably have to add some library to your cmake file

[edit:] stahta01 was faster....

Offline jury

  • Multiple posting newcomer
  • *
  • Posts: 18
Re: Undefined reference
« Reply #3 on: May 08, 2021, 06:25:02 am »
Got it.
Thank you.

(its strange then, that it builds fine when run from command line and fails through code::blocks, must dig in more)
« Last Edit: May 08, 2021, 06:32:30 am by jury »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7576
    • My Best Post
Re: Undefined reference
« Reply #4 on: May 09, 2021, 01:49:29 am »
Got it.
Thank you.

(its strange then, that it builds fine when run from command line and fails through code::blocks, must dig in more)

Post the external command line that works.
And, post the build log from CB that fails.

Tim S.

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline jury

  • Multiple posting newcomer
  • *
  • Posts: 18
Re: Undefined reference
« Reply #5 on: May 10, 2021, 10:20:43 pm »
I'm not sure what you mean by external command that works. Its just "make" that works :)
So I put make -n here:

https://pastebin.pl/view/35e5d4de

And here is the build log from code::blocks:

https://pastebin.pl/view/c79a1082

And these are the error lines from this build log:
Code
gmake[2]: *** No rules for object '/usr/lib64/libpython2.7.a', required by 'gemrb/gemrb'. Stop.
gmake[1]: *** [CMakeFiles/Makefile2:1297: gemrb/CMakeFiles/gemrb.dir/all] Error 2
gmake: *** [/home/jury/gry/gemrb-cb/build/Makefile:136: all] Error 2

I quite do not understand why it tries to build libpython2.7.a, especially that I have devel package installed in the system. So I tried to search for this library and found it, and I simply copied libpython2.7.a to /usr/lib64. And then when tried to build this project again I got the undefined reference from the opening post. But after your answers I understood that its not best path so I deleted libpython2.7.a from /usr/lib64.

(there was a lot of text in my native language in this build log from code::blocks, I hope I translated all to english, but if I have missed something just let me know)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7576
    • My Best Post
Re: Undefined reference
« Reply #6 on: May 11, 2021, 12:23:21 am »
My browser says possible security threat on website.

So, I am not going to be able to help you.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Undefined reference
« Reply #7 on: May 11, 2021, 09:04:40 am »
The two related parts are
CB:
Code
[ 13%] Built target CHUImporter
gmake[2]: *** No rules for object '/usr/lib64/libpython2.7.a', requred by 'gemrb/gemrb'. Stop.
gmake[1]: *** [CMakeFiles/Makefile2:1297: gemrb/CMakeFiles/gemrb.dir/all] Error 2
gmake: *** [/home/jury/gry/gemrb-cb/build/Makefile:136: all] Error 2
/usr/bin/gmake  -f gemrb/plugins/GUIScript/CMakeFiles/GUIScript.dir/build.make gemrb/plugins/GUIScript/CMakeFiles/GUIScript.dir/depend

make:
Code
make -s -f gemrb/plugins/CHUImporter/CMakeFiles/CHUImporter.dir/build.make gemrb/plugins/CHUImporter/CMakeFiles/CHUImporter.dir/depend
cd /home/jury/gry/gemrb-pc/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/jury/gry/gemrb-pc /home/jury/gry/gemrb-pc/gemrb/plugins/CHUImporter /home/jury/gry/gemrb-pc/build /home/jury/gry/gemrb-pc/build/gemrb/plugins/CHUImporter /home/jury/gry/gemrb-pc/build/gemrb/plugins/CHUImporter/CMakeFiles/CHUImporter.dir/DependInfo.cmake --color=
make -s -f gemrb/plugins/CHUImporter/CMakeFiles/CHUImporter.dir/build.make gemrb/plugins/CHUImporter/CMakeFiles/CHUImporter.dir/build
/usr/bin/cmake -E cmake_echo_color --switch= --progress-dir=/home/jury/gry/gemrb-pc/build/CMakeFiles --progress-num=12 "Built target CHUImporter"

this is strange... have you installed python 2.7?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7576
    • My Best Post
Re: Undefined reference
« Reply #8 on: May 11, 2021, 03:19:10 pm »
Why is it that nearly every [NEW] poster posts from "Build Messages" instead of "Build Log"?

Tim S.
« Last Edit: May 11, 2021, 03:39:39 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Undefined reference
« Reply #9 on: May 11, 2021, 04:55:51 pm »
Because C::B fails to present the information in a good way.
I think we should ditch "Build messages" and improve the "Build log", but I haven't found the time to think about it a bit more.
As a minimum clicking on errors/warnings/infos in the "Build log" should work the same way as clicking in the "Build messages".
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline jury

  • Multiple posting newcomer
  • *
  • Posts: 18
Re: Undefined reference
« Reply #10 on: May 12, 2021, 10:57:05 pm »
this is strange... have you installed python 2.7?

Yes. I have python2.7-devel installed fine. When building this project from command line it finds python2.7 and the build process goes OK.

Why is it that nearly every [NEW] poster posts from "Build Messages" instead of "Build Log"?

I do not understand this. What I have presented is "Build Log". I clicked "Build log" tab in Code::Blocks, then pressed Ctrl-a and from right-button menu I selected "Copy selection to clipboard".

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7576
    • My Best Post
Re: Undefined reference
« Reply #11 on: May 13, 2021, 12:03:19 am »
this is strange... have you installed python 2.7?

Yes. I have python2.7-devel installed fine. When building this project from command line it finds python2.7 and the build process goes OK.

Why is it that nearly every [NEW] poster posts from "Build Messages" instead of "Build Log"?

I do not understand this. What I have presented is "Build Log". I clicked "Build log" tab in Code::Blocks, then pressed Ctrl-a and from right-button menu I selected "Copy selection to clipboard".

You are likely right; I do not use cmake.

I just notice you are using "make" in the one that work and "/usr/bin/gmake" in the one that fails.
Could this be the cause?
What is the full path to "make"? Could you try to set that as the CB make path?

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline jury

  • Multiple posting newcomer
  • *
  • Posts: 18
Re: Undefined reference
« Reply #12 on: May 14, 2021, 10:00:48 pm »
I just notice you are using "make" in the one that work and "/usr/bin/gmake" in the one that fails.
Could this be the cause?
What is the full path to "make"? Could you try to set that as the CB make path?

Thanks for suggestion.
Full path to "make" is /usr/bin/make.
And as I could not find where to set path to "make" in Code::Blocks (except Settings->Compiler->Toolchain executables, which has no effect for cmake builds as I've learned from this thread) so I decided to do some trick:
- move "gmake" somewhere else for a while
- create symbolic link named "qmake" pointing to "make"
- try to build the project in CB
And to my surprise when I checked this "qmake", its nothing else than the symbolic link to "make" :(

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Undefined reference
« Reply #13 on: May 14, 2021, 10:13:24 pm »
And as I could not find where to set path to "make" ...
Project -> Build options -> your target -> "Make" commands.
But this is done by cmake and they should already be correct.
It doesn't hurt if you double check them of course.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline jury

  • Multiple posting newcomer
  • *
  • Posts: 18
Re: Undefined reference
« Reply #14 on: May 14, 2021, 10:35:59 pm »
Project -> Build options -> your target -> "Make" commands.

Thanks!