Author Topic: link GMP library when using codeblocks  (Read 6609 times)

Offline mahaju

  • Multiple posting newcomer
  • *
  • Posts: 25
link GMP library when using codeblocks
« on: December 09, 2011, 01:06:27 pm »
Hello everyone
I am using Codeblocks 8.02 in Puppy Linux
I have gcc and GMP library installed
When I compile a program that GMP header file through the command line, I need to invoke the GMP library by giving this command

gcc -o oufile codefile.c -lgmp

How do I set the -lgmp parameter if I want to compile my program from codeblocks?

Thanks in advance

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9595
Re: link GMP library when using codeblocks
« Reply #1 on: December 09, 2011, 02:21:39 pm »
How do I set the -lgmp parameter if I want to compile my program from codeblocks?
Create a project, go to the linker tab in the project options, add "gmp" as linker library.

I also suggest you consult the C::B manual for some screenshots:
http://www.codeblocks.org/docs/main_codeblocks_en.html
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline mahaju

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: link GMP library when using codeblocks
« Reply #2 on: December 20, 2011, 09:29:32 am »
Hi
When I try to add new files to a project it shows a box saying adding files to the project and then sort of stops there
Here's a screenshot
What is the problem here?
PS: I am running this in VMWare

[attachment deleted by admin]

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: link GMP library when using codeblocks
« Reply #3 on: December 20, 2011, 06:25:59 pm »
I cannot say whether or not this is the problem, however I would suggest you try updating Code::Blocks to at least version 10.05 (8.02 is quite old, and many features have been fixed/added since then).

Offline mahaju

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: link GMP library when using codeblocks
« Reply #4 on: December 21, 2011, 02:32:04 am »
Thank you for the reply
however, I found out how to solve this particular problem
Just ignore the dialogue box that appears in the front, click on the one in the back and check the debug and/or release check boxes and press OK
Also I was not able to figure out how to get Codeblocks 10 for Puppy Linux 5.2.8 so I am using this one, since it is available as .pet package in the forums
« Last Edit: December 21, 2011, 02:33:43 am by mahaju »

Offline mahaju

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: link GMP library when using codeblocks
« Reply #5 on: December 28, 2011, 08:26:43 am »
Hello everyone
Please don't mind, but I have a few questions for Mr McFly
1. I guess you mean compiler properties and not the project properties?
2. Although it's not directly related to codeblocks, kindly tell me how to do something similar to adding -lgmp, but with my own library, in Windows. That is, I want to link to a library that I compile, in Windows through the command line. If possible please give me some ideas on this. One more thing, the --help parameter in gcc does not show -lgmp (nor -l), but it still works. Is there a complete list of all the parameters of gcc, possibly with some simple to understand explanations (and by this I mean besides the gcc website)? What is the gcc option that allows linking (for example, -S gives me the assembly file, -c gives me the object file after assembly but does no linking, so I still don't get an executable, and not specifying anything seems to do all 3 steps, create assembly file, create object file and link everything together to get an executable. So I if I have to do these steps individually, how to I do the linking part? )
Please don't mind even if these questions are not exactly codeblocks specific
Thank you for your time

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9595
Re: link GMP library when using codeblocks
« Reply #6 on: December 28, 2011, 04:35:42 pm »
1. I guess you mean compiler properties and not the project properties?
Yes, through the project options, you can also get to the build options, which include compiler and linker options. So it's always a good starting point.

2. Although it's not directly related to codeblocks, kindly tell me how to do something similar to adding -lgmp, but with my own library, in Windows.
You should try to understand / read yourself into how a compiler an linker works. Basically it's always the same for the linker: It needs to know where the library is (that's what the include directories for the linker are for), how the library is called and in which order it is required to link against.

The linker option -L[FOLDER] is an equivalent to adding directories to the linker include folders in C::B. No need for "-L". The linker option -l[library name] is an equivalent for adding the library to the linker options to link against. No need for the "-l".

I always strongly recommend before starting to use an IDE do such stuff on the command line to understand the principles of compilation / linking. And IDE won't help you to teach this, it helps you in case you already know what to do to easily set it up.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline mahaju

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: link GMP library when using codeblocks
« Reply #7 on: December 28, 2011, 04:58:36 pm »
Thank you very much
I have sorted out most of my problems related to linking an external library, but few issues are still remaining and I am looking into them
I hope I can drop in here later if I have any other problems
Thank you for your help