{"id":1655,"date":"2022-08-30T15:18:20","date_gmt":"2022-08-30T15:18:20","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/c-error-undefined-reference-to-pow-in-eclipse-ide-can-use-it-in-main-function-but-not-in-others-i-am-using-lm-compiler-flag-closed-collection-of-common-programming-erro\/"},"modified":"2022-08-30T15:18:20","modified_gmt":"2022-08-30T15:18:20","slug":"c-error-undefined-reference-to-pow-in-eclipse-ide-can-use-it-in-main-function-but-not-in-others-i-am-using-lm-compiler-flag-closed-collection-of-common-programming-erro","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/c-error-undefined-reference-to-pow-in-eclipse-ide-can-use-it-in-main-function-but-not-in-others-i-am-using-lm-compiler-flag-closed-collection-of-common-programming-erro\/","title":{"rendered":"C error &#8211; undefined reference to pow in Eclipse IDE &#8211; can use it in &#39;main&#39; function but not in others. I AM using &ldquo;-lm&rdquo; compiler flag [closed]-Collection of common programming errors"},"content":{"rendered":"<pre><code>#include \n#include \n#include \n\nconst short int Z = 2;\n\nconst int parts = 1000;\nconst double epsilon = 1e-5;\n\ntypedef double (*func_n_l_r)(int, double);\n\ndouble R_nl(int n, int l, double r) {\n    return 2 * pow(Z, 1.5) * exp(-r * Z );\n}\n\nint main(void) {\n    printf(\"%f\",pow(3,2));\n    return EXIT_SUCCESS;\n}\n<\/code><\/pre>\n<p>In main it compiles and displays the results (if I comment out the R_nl function, of course), but it gives me an error in the R_nl function (same with the <code>exp<\/code> function).<\/p>\n<p>Using Eclipse Juno for c\/c++ developments.<\/p>\n<p>[EDIT]: Using -lm flag.<\/p>\n<p>[EDIT]: Using gcc compiler with arguments <code>-lm -E -P -v -dD \"${plugin_state_location}\/specs.c\"<\/code> from Eclipse IDE &#8211; linux ubuntu 13.04.<\/p>\n<p>[EDIT]: Compiler output, and i don&#8217;t know why it doesn&#8217;t see the <code>-lm<\/code> argument i gave it in the configurations&#8230;. \ud83d\ude10<\/p>\n<pre><code>08:13:52 **** Incremental Build of configuration Debug for project Helium ****\nInfo: Configuration \"Debug\" uses tool-chain \"MinGW GCC\" that is unsupported on this system, attempting to build anyway.\nInfo: Internal Builder is used for build\ngcc -o Helium src\/Helium.o \nsrc\/Helium.o: In function `R_nl':\n\/home\/shefuto\/Dropbox\/pt_sqala\/Master 2\/sem2\/nagy\/Helium\/Debug\/..\/src\/Helium.c:28: undefined reference to `pow'\n<\/code><\/pre>\n<p>[EDIT]: SOLVED : http:\/\/www.eclipse.org\/forums\/index.php?t=msg&amp;th=68204\/<\/p>\n<p>Apparently there&#8217;s a special options page for that, where you can specify linker arguments, where &#8216;m&#8217; is the library you want to add, and it adds the option <code>-lm<\/code> automatically.<\/p>\n<ol>\n<li>\n<p>You need to add -lm flag to compile(linker) command string.<\/p>\n<pre><code>gcc -lm .\/main.c\n<\/code><\/pre>\n<p>See man pow<\/p>\n<pre><code>   #include \n\n   double pow(double x, double y);\n   float powf(float x, float y);\n   long double powl(long double x, long double y);\n\n   Link with -lm. \/\/<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:25:17. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>#include #include #include const short int Z = 2; const int parts = 1000; const double epsilon = 1e-5; typedef double (*func_n_l_r)(int, double); double R_nl(int n, int l, double r) { return 2 * pow(Z, 1.5) * exp(-r * Z ); } int main(void) { printf(&#8220;%f&#8221;,pow(3,2)); return EXIT_SUCCESS; } In main it compiles and displays [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1655","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1655"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1655\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}