From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vb0-x229.google.com (mail-vb0-x229.google.com [IPv6:2607:f8b0:400c:c02::229]) by dpdk.org (Postfix) with ESMTP id 4EEF0594B for ; Fri, 3 Jan 2014 11:47:27 +0100 (CET) Received: by mail-vb0-f41.google.com with SMTP id p14so7724645vbm.0 for ; Fri, 03 Jan 2014 02:48:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=wVi6nh0UYnC4htbnwb0Tn5PMuwlD6zpnJzU/i94sYWU=; b=MaYHY4csEbW4JdpKEU96Wo+NPG2lGcqEoQY0XwS9AXF1WdX9qCrePKYgtpflCYVlgO Uet3NO8cCy+GniCNlq5VtEb6vmlbd8Ue5mSbP+1cxW0XZXPmYm7+A7dbzYItq11ASN3L IJhWwoAnq8HNo4ssEZp7oaoA0STn31xuHjVhnA5mgDSOesLsoCCMilpwLZMZr2Piu7AA jDc+0+RnmJJlChwGqdd73Rs96j4z7LPzSmOs8OE2/07j28Z3ly/BXWYm9GrAj92SBrQx li0p+PhVLP28IYrGTCWfY2l20T91yc9RLo0VOFVx+j0TSfcJXiKMuvfIEThPil2mUxh+ eZ8g== MIME-Version: 1.0 X-Received: by 10.58.248.198 with SMTP id yo6mr10109vec.40.1388746117987; Fri, 03 Jan 2014 02:48:37 -0800 (PST) Received: by 10.58.77.173 with HTTP; Fri, 3 Jan 2014 02:48:37 -0800 (PST) In-Reply-To: References: Date: Fri, 3 Jan 2014 14:18:37 +0330 Message-ID: From: Hamid Ramazani To: Stefan Baranoff Content-Type: text/plain; charset=ISO-8859-1 Cc: dev@dpdk.org Subject: Re: [dpdk-dev] g++: undefined reference to X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Jan 2014 10:47:27 -0000 Hey Stefan, Thanks a lot for your answer. I followed your instructions, and have following problem. Also I'd like to mention that on my system: echo $RTE_SDK /home/hamid/dpdk/dpdk-1.5.1r1 and echo $RTE_TARGET x86_64-default-linuxapp-gcc I get following error now: ######################################## /home/hamid/dpdk/dpdk-1.5.1r1/x86_64-default-linuxapp-gcc/lib/librte_eal.a(eal_timer.o): In function `rte_eal_timer_init': eal_timer.c:(.text+0x42c): undefined reference to `clock_gettime' eal_timer.c:(.text+0x468): undefined reference to `clock_gettime' /home/hamid/dpdk/dpdk-1.5.1r1/x86_64-default-linuxapp-gcc/lib/librte_eal.a(eal_common_nonpci_devs.o):(.data+0x8): undefined reference to `rte_pmd_ring_init' collect2: ld returned 1 exit status make: *** [all] Error 1 ######################################## my sample.cpp is like this: ######################################## #include #include extern "C"{ #include #include } #include class Runner { public: Runner(){}; void run(int argc, char** argv) { std::cout << std::string("Calling rte_eal_init") << std::endl; rte_eal_init(argc, argv); std::cout << std::string("Called rte_eal_init - done now!") << std::endl; }; }; int main(int argc, char** argv) { Runner* runner = new Runner(); runner->run(argc, argv); delete runner; exit(0); } ######################################## and my Makefile is like this: all: g++ -m64 -pthread -march=native -DRTE_MACHINE_CPUFLAG_SSE -DRTE_MACHINE_CPUFLAG_SSE2 -DRTE_MACHINE_CPUFLAG_SSSE3 -DRTE_COMPILE_TIME_CPUFLAGS=RTE_CPUFLAG_SSE,RTE_CPUFLAG_SSE2,RTE_CPUFLAG_SSSE3 -I/home/hamid/dpdk/dpdk-1.5.1r1/examples/sample/build/include -I/home/hamid/dpdk/dpdk-1.5.1r1/x86_64-default-linuxapp-gcc/include -include /home/hamid/dpdk/dpdk-1.5.1r1/x86_64-default-linuxapp-gcc/include/rte_config.h -O3 -W -Wall -Werror -Wmissing-declarations -Wpointer-arith -Wcast-align -Wcast-qual -Wformat-nonliteral -Wformat-security -Wundef -Wwrite-strings -Wl,-melf_x86_64 -Wl,-export-dynamic sample.cpp -o sample -Wl,-L/home/hamid/dpdk/dpdk-1.5.1r1/examples/sample/build/lib -Wl,-L/home/hamid/dpdk/dpdk-1.5.1r1/x86_64-default-linuxapp-gcc/lib -Wl,-L/home/hamid/dpdk/dpdk-1.5.1r1/x86_64-default-linuxapp-gcc/lib -Wl,-lrte_kni -Wl,-lrte_pmd_e1000 -Wl,-lrte_pmd_ixgbe -Wl,-lrte_mbuf -Wl,-lrte_cmdline -Wl,-lrte_timer -Wl,-lrte_hash -Wl,-lrte_lpm -Wl,--start-group -Wl,-lethdev -Wl,-lrte_malloc -Wl,-lrte_mempool -Wl,-lrte_ring -Wl,-lrte_eal -Wl,-ldl -Wl,--end-group ######################################## Your advice is much appreciated. Thanks in advance. --Hamid On 1/3/14, Stefan Baranoff wrote: > Hamid, > > I apologize for the earlier slight misdirection; I was on my phone and > trying to respond from memory. The actual answer is really to use > -lrte_static_library_name and not referencing the .o files. Sorry!!! > > To get this I ran 'make -n' on the 'Hello World' example app (careful, > there's the gcc command and then another "&& echo " with the command again > in there when you run make -n and you really only need the real gcc call, > not the echo). Below is a sample g++ command that works for me just running > against a quick C++ files that does an 'rte_eal_init()' so you may need to > extend it to handle more complex cases. > > Note I've stripped out a few pieces that may actually matter and left in > some don't but work for the moment for this (very) simple case. I don't > claim to be a GCC guru so we may encounter random failures down the road > with our approach and are ready to accept that risk until we can get > someone to review the effect of the removed options. Please take the > following commands with a grain of salt. The primary omissions are the > -Wl,-Map and --cref along with stripping out a few warnings > (-Wstrict-prototypes, -Wmissing-prototypes, > -Wold-style-definition, -Wnested-externs). > > Please note that near the end but before the -Wl,-L options there is the > reference to my main file "sample.cpp" and the '-o sample' option for my > file 'sample.cpp' that you would replace - this could be broken out better > and I'm sure the default Makefile syntax could be extended to support c++ > but I'll leave that to someone else who is better with Make/GCC to > implement properly. > > all: > g++ -m64 -pthread -march=native -DRTE_MACHINE_CPUFLAG_SSE > -DRTE_MACHINE_CPUFLAG_SSE2 -DRTE_MACHINE_CPUFLAG_SSSE3 > -DRTE_COMPILE_TIME_CPUFLAGS=RTE_CPUFLAG_SSE,RTE_CPUFLAG_SSE2,RTE_CPUFLAG_SSSE3 > -I/data/home/sbaranoff/DPDKPlayground/dpdk-1.3.1r2/examples/helloworld/build/include > -I/home/sbaranoff/DPDKPlayground/dpdk-1.3.1r2//x86_64-default-linuxapp-gcc/include > -include > /home/sbaranoff/DPDKPlayground/dpdk-1.3.1r2//x86_64-default-linuxapp-gcc/include/rte_config.h > -O3 -W -Wall -Werror -Wmissing-declarations -Wpointer-arith -Wcast-align > -Wcast-qual -Wformat-nonliteral -Wformat-security -Wundef -Wwrite-strings > -Wl,-melf_x86_64 -Wl,-export-dynamic sample.cpp -o sample > -Wl,-L/data/home/sbaranoff/DPDKPlayground/dpdk-1.3.1r2/examples/helloworld/build/lib > -Wl,-L/home/sbaranoff/DPDKPlayground/dpdk-1.3.1r2//x86_64-default-linuxapp-gcc/lib > -Wl,-L/home/sbaranoff/DPDKPlayground/dpdk-1.3.1r2//x86_64-default-linuxapp-gcc/lib > -Wl,-lrte_kni -Wl,-lrte_pmd_e1000 -Wl,-lrte_pmd_ixgbe -Wl,-lrte_mbuf > -Wl,-lrte_cmdline -Wl,-lrte_timer -Wl,-lrte_hash -Wl,-lrte_lpm > -Wl,--start-group -Wl,-lethdev -Wl,-lrte_malloc -Wl,-lrte_mempool > -Wl,-lrte_ring -Wl,-lrte_eal -Wl,-ldl -Wl,--end-group > > > This is probably complete overkill and should be tailored to your use case > but it is heading in the right direction! > > Here's the C++ file I compiled with it (yes, I should use RAII and that > stack and not 'new' -- I know, Java habits die hard): > #include > #include > #include > #include > #include > > class Runner > { > public: > Runner(){}; > void run(int argc, char** argv) > { > std::cout << std::string("Calling rte_eal_init") << std::endl; > rte_eal_init(argc, argv); > std::cout << std::string("Called rte_eal_init - done now!") << > std::endl; > }; > }; > > int main(int argc, char** argv) > { > Runner* runner = new Runner(); > runner->run(argc, argv); > delete runner; > exit(0); > } > > > Thanks, > Stefan > > > On Thu, Jan 2, 2014 at 4:52 PM, Stefan Baranoff > wrote: > >> Hamid, >> >> I have a c++ app that compiles but not with me right now. When I get home >> I'll send you a sample makefile. >> >> Stefan >> >> Sent from my smart phone; people don't make typos, Swype does! >> On Jan 2, 2014 11:40 AM, "Hamid Ramazani" wrote: >> >>> Stefan, >>> >>> I did: >>> >>> find `pwd` | egrep "[ao]$" >> liblistWithDuplicates.txt >>> then opened it and added \ to the end of each line and added those >>> libraries to my g++ arguments in Makefile after helloClass.o >>> >>> Now, in output I get two types of errors: >>> multiple definition of .... >>> undefined reference to ... >>> >>> In order to remove duplicate object file names, I wrote a short python >>> script which is attached, >>> to create liblistNoDuplicates.txt, >>> but still I get the same errors. >>> >>> >>> I'd really appreciate your advice. >>> >>> All the Best, >>> Hamid >>> >>> >>> On 1/2/14, Stefan Baranoff wrote: >>> > Hamid, >>> > >>> > I do not think your attachments made it through but it looks like you >>> are >>> > not linking the DPDK object files in this line: >>> > g++ helloClass.o >>> > -I/home/hamid/dpdk/dpdk-1.5.1r1/x86_64-default-linuxapp-gcc/include >>> > -lstdc++ >>> > >>> > There would need to be many more files beyond helloClass.o listed. Try >>> > adding the relevant DPDK object files (I do not have the path off hand >>> but >>> > I believe they are in the "build" folder) and recompiling. The files >>> > you >>> > need to add are those built when your build DPDK itself. >>> > >>> > This is similar to missing -lpcap if compiling against libpcap but in >>> this >>> > case you need to link against object files, not a shared library. >>> > >>> > Good luck! >>> > Stefan >>> > >>> > Sent from my smart phone; people don't make typos, Swype does! >>> > On Jan 2, 2014 4:35 AM, "Hamid Ramazani" wrote: >>> > >>> >> Hi, >>> >> >>> >> I wanted to write a simple program using class (object oriented). >>> >> I've >>> >> attached my helloClass.cpp and also Makefile. after runnig make I get >>> >> below errors. >>> >> I think: >>> >> 1. it is the problem of using c code in c++ >>> >> 2. I've used extern "C" in helloClass.cpp >>> >> 3. Should I recompile the DPDK from source with gcc -c argument for >>> >> compatibility with g++? >>> >> >>> >> Thanks in advance. >>> >> >>> >> g++ -c helloClass.cpp >>> >> -I/home/hamid/dpdk/dpdk-1.5.1r1/x86_64-default-linuxapp-gcc/include >>> >> g++ helloClass.o >>> >> -I/home/hamid/dpdk/dpdk-1.5.1r1/x86_64-default-linuxapp-gcc/include >>> >> -lstdc++ >>> >> helloClass.o: In function `rte_lcore_id': >>> >> helloClass.cpp:(.text+0x7): undefined reference to >>> `per_lcore__lcore_id' >>> >> helloClass.o: In function `rte_get_master_lcore': >>> >> helloClass.cpp:(.text+0x15): undefined reference to >>> >> `rte_eal_get_configuration' >>> >> helloClass.o: In function `rte_lcore_is_enabled': >>> >> helloClass.cpp:(.text+0x2a): undefined reference to >>> >> `rte_eal_get_configuration' >>> >> helloClass.o: In function `HelloClass::HelloClass(int, char**)': >>> >> >>> helloClass.cpp:(.text._ZN10HelloClassC2EiPPc[_ZN10HelloClassC5EiPPc]+0x20): >>> >> undefined reference to `rte_eal_init' >>> >> >>> helloClass.cpp:(.text._ZN10HelloClassC2EiPPc[_ZN10HelloClassC5EiPPc]+0x4b): >>> >> undefined reference to `__rte_panic' >>> >> helloClass.o: In function `HelloClass::run()': >>> >> helloClass.cpp:(.text._ZN10HelloClass3runEv[HelloClass::run()]+0x3f): >>> >> undefined reference to `rte_eal_remote_launch' >>> >> helloClass.cpp:(.text._ZN10HelloClass3runEv[HelloClass::run()]+0x80): >>> >> undefined reference to `rte_eal_mp_wait_lcore' >>> >> collect2: ld returned 1 exit status >>> >> make: *** [helloClass.o] Error 1 >>> >> >>> >> >>> >> All the Best, >>> >> Hamid >>> >> >>> > >>> >> >