linbox icon indicating copy to clipboard operation
linbox copied to clipboard

Difficulties in compiling code which uses LinBox

Open vneiger opened this issue 7 years ago • 6 comments

Hello,

While writing code which involves some calls to functions from LinBox, I have encountered the following compiling issue, which I am unable to understand or fix; because of this I am currently unable to separate for example class declarations, definitions, and the main function in different files. It might be a simple misunderstanding of how to compile my files correctly...

Could someone please tell me if this is the expected behaviour, and give me a rough explanation of (why this behaviour and) how to circumvent the issue? Thank you for your help.

Attached are three files giving a minimal example showing the behaviour, and the log showing errors during compilation (a lot of "multiple definitions"). In summary, the files are:

  • mwe.cc and mwe.h which includes some linbox file, say linbox/matrix/matrix-domain.h (and typically also contain a class definition and declaration, but actually empty files suffice to exhibit the issue)
  • mwe_main.cc which contains the main function and includes mwe.h .

Then, when I compile this, I use: g++ -I/usr/local/include -O2 -Wall -g -fopenmp -fabi-version=6 -mmmx -mpopcnt -msse -msse2 -msse3 -msse4.1 -msse4.2 -mavx -mavx2 -mfma -mbmi -mbmi2 -mfpmath=sse -std=gnu++11 -c mwe.cc g++ -I/usr/local/include -O2 -Wall -g -fopenmp -fabi-version=6 -mmmx -mpopcnt -msse -msse2 -msse3 -msse4.1 -msse4.2 -mavx -mavx2 -mfma -mbmi -mbmi2 -mfpmath=sse -std=gnu++11 -c mwe_main.cc g++ -o main mwe.o mwe_main.o -L/usr/local/lib -fopenmp -lopenblas -lgivaro -lgmp -lgmpxx -lntl -lmpfr -llinbox

Thank you very much. Best regards,

   Vincent N.

minimal_example.zip

vneiger avatar Nov 21 '17 14:11 vneiger

LinBox is a template library consisting almost entirely of header files. Unfortunately, a number of explicit function definitions are to be found in some of these headers. The solution currently is to confine your LinBox use to one compilation unit.

I removed the problem vis a vis commentator and args parsing whereupon numerous other "multiply defined" instances surfaced. I'll launch a ticket to address the issue. It'll take a while.

Best, -bds

On Tue, Nov 21, 2017 at 9:27 AM, vneiger [email protected] wrote:

Hello,

While writing code which involves some calls to functions from LinBox, I have encountered the following compiling issue, which I am unable to understand or fix; because of this I am currently unable to separate for example class declarations, definitions, and the main function in different files. It might be a simple misunderstanding of how to compile my files correctly...

Could someone please tell me if this is the expected behaviour, and give me a rough explanation of (why this behaviour and) how to circumvent the issue? Thank you for your help.

Attached are three files giving a minimal example showing the behaviour, and the log showing errors during compilation (a lot of "multiple definitions"). In summary, the files are:

  • mwe.cc and mwe.h which includes some linbox file, say linbox/matrix/matrix-domain.h (and typically also contain a class definition and declaration, but actually empty files suffice to exhibit the issue)
  • mwe_main.cc which contains the main function and includes mwe.h .

Then, when I compile this, I use: g++ -I/usr/local/include -O2 -Wall -g -fopenmp -fabi-version=6 -mmmx -mpopcnt -msse -msse2 -msse3 -msse4.1 -msse4.2 -mavx -mavx2 -mfma -mbmi -mbmi2 -mfpmath=sse -std=gnu++11 -c mwe.cc g++ -I/usr/local/include -O2 -Wall -g -fopenmp -fabi-version=6 -mmmx -mpopcnt -msse -msse2 -msse3 -msse4.1 -msse4.2 -mavx -mavx2 -mfma -mbmi -mbmi2 -mfpmath=sse -std=gnu++11 -c mwe_main.cc g++ -o main mwe.o mwe_main.o -L/usr/local/lib -fopenmp -lopenblas -lgivaro -lgmp -lgmpxx -lntl -lmpfr -llinbox

Thank you very much. Best regards,

Vincent N.

minimal_example.zip https://github.com/linbox-team/linbox/files/1491679/minimal_example.zip

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/linbox-team/linbox/issues/82, or mute the thread https://github.com/notifications/unsubscribe-auth/ADk6I30Y8mSUuAflJFawRvYLLwTI1OpRks5s4t24gaJpZM4Ql7DX .

bdsaunders avatar Nov 22 '17 17:11 bdsaunders

Thank you very much for your answer and explanation. (I did find some rather old messages on linbox-devel mentioning this but I did not know if these messages were still correct today.)

So, for now I'll continue with the solution you give, this is not really a problem. Since this may be confusing for new LinBox users in general, it might be helpful to have a short warning about this somewhere visible (README?).

Best,

 Vincent

vneiger avatar Nov 22 '17 18:11 vneiger

Hi again, Vincent,

I agree we should comment on this.

In fact, even if we do adjust to allow separate compilation, I would still suggest compiling all your linbox-using code in one compilation unit. This is to avoid code bloat. Many templates will be instantiated identically in each compilation unit. That is a waste of space even though the compiler will be happy. You can still have many files using linbox. Then compile a file including them, like: #include "mwe.cc" #include "mwe-main.cc"

Remarks to linbox team:

The only place I've found in fflas/ffpack with this issue is utils/args-parser.h. Perhaps we should adjust that, since fflas/ffpack likes to be a headers only package.

The places in linbox I've found the issue are util/commentator.h and util/args-parser.h and matrix/matrixdomain/blas-matrix.h (checkBlasApply). ...I didn't search further. For linbox we can put a few things in .C files and have the build put them in liblinbox. As it is, about the only thing we compile is diophantine-solver. Basically it's there as a demo.

Should we support linking of separately compiled linbox applications? It'd be simple enough (except for commentator) using anonymous namespaces, I believe.

On Wed, Nov 22, 2017 at 1:29 PM, vneiger [email protected] wrote:

Thank you very much for your answer and explanation. (I did find some rather old messages on linbox-devel mentioning this but I did not know if these messages were still correct today.)

So, for now I'll continue with the solution you give, this is not really a problem. Since this may be confusing for new LinBox users in general, it might be helpful to have a short warning about this somewhere visible (README?).

Best,

Vincent

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/linbox-team/linbox/issues/82#issuecomment-346436242, or mute the thread https://github.com/notifications/unsubscribe-auth/ADk6I_RpYQzoiBg6kimDFJqMIeVq596kks5s5GgOgaJpZM4Ql7DX .

bdsaunders avatar Nov 22 '17 21:11 bdsaunders

Hi Dave, (Late answer...) Thank you for your advice about keeping the linbox-using code in one compilation unit, I had not realized this potential waste of space. Best, Vincent

vneiger avatar Nov 30 '17 11:11 vneiger

Hi, We should definitely support the usage that Vincent suggested. In order to avoid the compilation error, we should enforce that every function is either defined inline or static. In fflas-ffpack, we use inlining everywhere and a test of the test-suite explicitely tries to do multiple compilation to ensure that no new function gets added without inlining. As for the global variables such as the commentator (I don't know any other instance), we could require to disable it for multiple compilations. Btw, I am quite unhappy with the presence of this global variable and would vote to get rid of it.

ClementPernet avatar Dec 13 '17 14:12 ClementPernet

I think I know how to get rid of the global variable when commentator is disabled. I'll do it.

On Wed, Dec 13, 2017 at 9:50 AM, Clément Pernet [email protected] wrote:

Hi, We should definitely support the usage that Vincent suggested. In order to avoid the compilation error, we should enforce that every function is either defined inline or static. In fflas-ffpack, we use inlining everywhere and a test of the test-suite explicitely tries to do multiple compilation to ensure that no new function gets added without inlining. As for the global variables such as the commentator (I don't know any other instance), we could require to disable it for multiple compilations. Btw, I am quite unhappy with the presence of this global variable and would vote to get rid of it.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/linbox-team/linbox/issues/82#issuecomment-351413050, or mute the thread https://github.com/notifications/unsubscribe-auth/ADk6I1QPBY2BO03EzGsvEsxcvg36_hehks5s_-Q8gaJpZM4Ql7DX .

bdsaunders avatar Dec 13 '17 18:12 bdsaunders