1

I'm almost certain this is a dupe, but I don't have even the base vocabulary to begin researching this question.

I have a few g++ linker flags that I'd like to make permanent as export variables in /etc/bash.bashrc.

Is it possible to do this for -D_WEBSOCKETPP_CPP11_STL_ -D_WEBSOCKETPP_NO_CPP11_REGEX_ -lboost_regex -lboost_system as in this answer for websocket++ https://stackoverflow.com/a/15469310/1382306 and -lmysqlcppconn for mysql connector c++ https://stackoverflow.com/a/11879650/1382306?

If so, please show me how. If not, please show me how to get started.

Community
  • 1
  • 1
  • Are you using `make` to compile, or just calling `g++` directly? – teppic Mar 28 '13 at 02:10
  • @teppic `g++` directly. Thank your for looking! –  Mar 28 '13 at 02:10
  • Ah, as for `make` you can just set `LDFLAGS`. An option would be to create a bash function or alias to include an environment variable that does the same thing. – teppic Mar 28 '13 at 02:12
  • @teppic Thank you! I will look into that. This is for pure laziness's sake. Would you mind expanding just a little to full answer? –  Mar 28 '13 at 02:15

1 Answers1

1

If you use make instead, there are various standard environment variables that are sent to the compiler. One is LDFLAGS, so for example:

$ export LDFLAGS='-Wl,--print-map'
$ make foo.cpp
g++   -Wl,--print-map  foo.cpp   -o foo      // default rule
[...]

Linker flags have to be passed separated by commas after -Wl.

Alternatively, you could make an alias or shell function to call g++ with an appropriate environment variable.

teppic
  • 8,039
  • 2
  • 24
  • 37