How to force gcc to link an unused static library

Use –whole-archive linker option. Libraries that come after it in the command line will not have unreferenced symbols discarded. You can resume normal linking behaviour by adding –no-whole-archive after these libraries. In your example, the command will be: g++ -o program main.o -Wl,–whole-archive /path/to/libmylib.a In general, it will be: g++ -o program main.o \ -Wl,–whole-archive … Read more

How do I view the value of an variable in C++?

On high optimization levels, the compiler can eliminate intermediate values, as you have seen here. There are a number of options: You can reduce the optimization level to make it easier for the debugger to keep track of things. -O0 is certain to work (but will be quite a lot slower), -O1 might work okay … Read more

Print template typename at compile time

To get a useful compile time name: Supposing you have some unknown type named ‘T’. You can get the compiler to print it’s type by using it horribly. For example: typedef typename T::something_made_up X; The error message will be like: error: no type named ‘something_made_up’ in ‘Wt::Dbo::ptr<trader::model::Candle>’ The bit after ‘in’ shows the type. (Only … Read more

static_assert fails compilation even though template function is called nowhere

The standard says in [temp.res]/8 No diagnostic shall be issued for a template definition for which a valid specialization can be generated. If no valid specialization can be generated for a template definition, and that template is not instantiated, the template definition is ill-formed, no diagnostic required. … [ Note: If a template is instantiated, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)