<html><body><div>I had a similar problem, what helped was these StackOverflow question <a href="https://stackoverflow.com/questions/35897290/what-is-the-right-order-of-linker-flags-in-gcc">https://stackoverflow.com/questions/35897290/what-is-the-right-order-of-linker-flags-in-gcc</a> and <a href="https://stackoverflow.com/questions/20731220/compile-error-gcc-lpthread-position">https://stackoverflow.com/questions/20731220/compile-error-gcc-lpthread-position</a>.</div><div><br></div><div>In a nutshell, try moving the -lpapi "option" to the last position,  so something like this:  $(CXX) $(CXXFLAGS) -O3 -Wall -o $@ counter-spinner.cpp harness.cpp -lpapi<br><br></div><div>From what I understand (and i may be wrong on this), the -l option is processed as soon as it is encountered, so if it is used before mentioning the files that use the library, it is discarded.</div><div>So it s not really an option or switch of gcc, as the form -l would suggest, and more like a command.</div><div>It used to work on older gcc versions, but then they changed some default properties or something.<br></div><div><br></div><div>Karel Maděra<br></div><aside>
---------- Původní e-mail ----------<br>
Od: Petr Tůma <petr.tuma@d3s.mff.cuni.cz><br>
Komu: William Tatarko <william.tatarko@gmail.com><br>
Datum: 20. 3. 2020 18:33:27<br>
Předmět: Re: [NSWI131] 03-counter-spinner - papi problem
</aside><br><blockquote data-email="petr.tuma@d3s.mff.cuni.cz">Hi,<br><br>this is seriously weird :-) and in fact exactly the same error I get if I omit "-lpapi" from the command line. (Why it is weird is because from the log you have sent, it is clear that "-lpapi" is there, and if the library file was missing, GCC would display an error message saying "cannot find -lpapi".)<br><br>What you can try to do is see what library file the "papi_avail" command uses, on my machine it is something like this:<br><br>> ldd $(which papi_avail)<br> linux-vdso.so.1 (0x...)<br>       libpapi.so.5 => /lib64/libpapi.so.5 (0x...)<br>        ...<br><br>This library obviously works, or the "papi_avail" command would not start. As the next step, you can try to use the library on the GCC command line directly:<br><br>> g++ -O3 -Wall /lib64/libpapi.so.5 -o counter-spinner counter-spinner.cpp harness.cpp<br><br>(Obviously, replace the library file name with whatever ldd shows on your system.)<br><br>If this also fails, and you do not see any obvious permission issues on the files involved, then I would recommend to simply use a lab computer (remote access should work) otherwise you will waste too much time with this.<br><br>Petr<br><br><br>On 20/03/2020 10:41, William Tatarko wrote:<br>> Hello,<br>> <br>> thank you very much for the answer, but I am still unable to make ti work.<br>> <br>> Initially I tried to install from the Git repository. From the src folder I ran "./configure", "make" and then I tried "make test", which resulted in "PASSED". Finally I ran "make install" with sudo, because otherwise I got a permission denied message. Later I also tried "make install-all" and papi versions 6.0 and 5.7 (which allegedly worked for a random person on the web). I also tried to install papi-tools using the "apt install" command (I am running Ubuntu).<br>> <br>> Command "papi_available" show no available events, which was suspicious. After I ran "papi_native_avail" I got a message that essentially said that with paranoid=3 it cannot work. This was weird, because I got this error message when I was installing papi for the first time and I had done what the error message had asked me to do, after which I have not seen this error message (until running "papi_native_avail"). Anyway, I executed "sudo sh -c 'echo -1 >/proc/sys/kernel/perf_event_paranoid" and then "papi_available" suddenly showed 59 available events and "papi_native_avail" stoped complaining. However the compilation still throws the same error (it is in the attachment).<br>> <br>> I believe it was initially installed (at least) into "/usr/local/lib/" directory. I tried to copy it also to different folders ("/lib/", "/lib64/", "/usr/lib/" and "/usr/lib64/") but it did not helped either. I also tried to explicitly set the path by modifying the compilation command to "$(CXX) $(CXXFLAGS) -O3 -Wall -L/usr/local/lib/ -lpapi -o $@ counter-spinner.cpp harness.cpp", but still no luck.<br>> <br>> Best regards<br>> William<br>> <br>> On Fri, Mar 20, 2020 at 8:09 AM Petr Tůma <petr.tuma@d3s.mff.cuni.cz <mailto:petr.tuma@d3s.mff.cuni.cz>> wrote:<br>> <br>>     Hi,<br>> <br>>     this sounds like a PAPI installation problem. It's hard to debug with little information, but these are the steps I would try (if they do not help, please include exact log of what commands you were running and what was the output):<br>> <br>>     - Did you install using your distribution packages, or from the Git repository ? If the latter, did you do 'make install' ?<br>> <br>>     - Do the 'papi_avail' and 'papi_native_avail' commands work, when launched from any directory (not just the build directory) ?<br>> <br>>     - Do you have the PAPI library in your system default library path, e.g. /lib64/libpapi.so.* ?<br>> <br>>     Hope this puts you on the right path, Petr<br>> <br>> <br>>     On 19/03/2020 19:19, William Tatarko wrote:<br>>     > Hello,<br>>     ><br>>     > I have some trouble with papi. I installed it without any problem (and even passed the original papi test). However when I try to run the make for the c++ version (without modifying the code at all) I got several errors like "undefined reference to `PAPI_*', where * is "stop", "start", "library_init" and many more. I also tried the java version (again without changing the code), but the run.sh script resulted in "error: PAPI library initialization: Invalid argument (-1)". I am probably doing something terribly wrong, but after about 4 hours of debugging I have not figured it out.<br>>     ><br>>     > Can anybody please help me?<br>>     ><br>>     > Best regards<br>>     > William<br>>     ><br>>     > _______________________________________________<br>>     > NSWI131 mailing list<br>>     > NSWI131@d3s.mff.cuni.cz <mailto:NSWI131@d3s.mff.cuni.cz><br>>     > https://d3s.mff.cuni.cz/mailman/listinfo/nswi131<br>>     ><br>> <br>_______________________________________________<br>NSWI131 mailing list<br>NSWI131@d3s.mff.cuni.cz<br>https://d3s.mff.cuni.cz/mailman/listinfo/nswi131<br></blockquote></body></html>