Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8156331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:55:03+00:00 2026-06-06T16:55:03+00:00

I am having a hard time figuring out what flags to pass to g++

  • 0

I am having a hard time figuring out what flags to pass to g++ when performing linking. Basically, I compile some code with these “standard” flags:

CXXFLAGS = -Wall -Wextra -Wconversion -pedantic -std=c++0x -O2

and, afterwards, I merge the produced .o files into several static libraries like so:

libxxx.a: xxx1.o xxx2.o ...
    ar rcs $@ $^
libyyy.a: yyy1.o yyy2.o ...
    ar rcs $@ $^
...

Questions:

  • Do I need to use the -static flag in CXXFLAGS when compiling the .o files?

After the static libraries are created, I want to link some compiled .o files together with some of these libraries in order to build an executable so I use this:

LINKER = g++
LIB_DIR = lib/linux
SYSTEM_LIBS = -lgmp
LDFLAGS = -Wall -L $(OUTPUT_DIR) -L $(LIB_DIR) $(SYSTEM_LIBS)
$(LINKER) $^ $(LDFLAGS) -lsvm -lUtils -lKinderedSpirits -o $@

exe:
    $(LINKER) o1.o o2.o $(LDFLAGS) -lxxx -lyyy -lzzz -o $@

Questions:

– Should I use the -static flag here?
– Does -Wall make any sense here or is it useful just for compiling?
– Are there any other “standard” flags that need to be passed to the linker, similar to the ones recommended for the compiler?

Also, during linking it’s giving me exceptions about undefined references from the GMP library. As far as I can tell, -lgmp is sent to the linker and it is installed on the system (I was able to compile a simple hello world which uses GMP from the command line) and libxxx.a libyyy.a libzzz.a are located in $(LIB_DIR). Maybe I should mention that the GMP symbols are used in libxxx.a.


UPDATE:

I managed to fix the undefined references for the GMP symbols. The issue was caused by the order in which I placed the libraries. Basically, as specified here, I need to reference the libraries that depend on GMP before -lgmp. Anyway, I’m still looking for answers to my 3 questions above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:55:06+00:00Added an answer on June 6, 2026 at 4:55 pm

    Q: Should I also use the -static flag here?
    A: Probably not necessary. This flag just makes it impossible to accidentally link in dynamic libraries.

    Q: Does -Wall make any sense here or is it useful just for compiling?
    A: I believe it’s just for compiling. (fyi, the capital W followed by the word “all” species you want all warnings during compilation)

    Q: Are there any other “standard” flags that need to be passed to the linker, similar to the ones recommended for the compiler?
    A: Not that I’m aware of. You can find common options here: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

    Are you running into any specific error you’d care to paste?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some hard time figuring out what's wrong in this simple code: This
Having a hard time figuring out why this alert code is being called once
I'm having a hard time figuring out the best way to pass simple values
I'm having a hard time figuring out how to pass by reference in Java.
I'm having a hard time figuring out why lseek doesn't work properly. Basically all
I am having a hard time figuring out how to code a series of
I am having a hard time figuring out some things about how Core Data
Git noob here. Having a hard time figuring out why git shows some files
I am having a hard time figuring out this piece of code marked in
I am new here, but I am having hard time figuring out how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.