Solution to undefined reference to in Linux

Source: Internet
Author: User
Tags uppercase letter

A project experiences code porting, porting from UNIX to Linux, compiling the environment, and learning something...
The first step is to transplant ace packages, third-party stuff, and get it done in a few minutes.
Step 2 transplant a platform component encapsulated by the company, refer to the ace package compilation Parameters
Compile and use these parameters:
G ++-fvisibility = hidden-fvisibility-inlines-hidden-w-wall-wpointer-Arith-O3-g-pipe-FPIC
Link to the dynamic library:
G ++-shared-O libdiccpt. so.1.0.0 .. /.. /src/public/reactor. O .. /.. /src/public/md5.o .. /.. /src/public/dicexceptions. O .. /.. /src/public/debug. O .. /.. /src/public/datacdr. O .. /.. /src/public/objectrefmgr. O .. /.. /src/configcpt. O .. /.. /src/configcpt/configfacade. O
.. /.. /Src/configcpt/configobjmgr. O .. /.. /src/configcpt/iconfig. O .. /.. /src/configcpt/iniconfig. O .. /.. /src/configcpt/xmlconfig. O .. /.. /src/logcpt/acelogoutput. O .. /.. /src/logcpt/logconfig. O .. /.. /src/logcpt/logfilebackup. O .. /.. /src/logcpt/logfilestream. O
.. /.. /Src/logcpt/logfilestreammap. O .. /.. /src/logcpt/logprocessor. O .. /.. /src/logcpt/logqueuetask. O .. /.. /src/logcpt/logmsgblockmgr. O .. /.. /src/logcpt/logmsgblock. O .. /.. /src/logcpt/logtime. O .. /.. /src/logcpt. O .. /.. /src/logcpt/shmlogoutput. o-wl,-e
-L.-L/public/abp_icc/release/lib-LDL-lpthread-LRT

Step 3: Compile the application:
When the application is finally linked, the message cannot be found.
G ++-FPIC-O voiceurge src/dcvoiceurgecheck. O src/dcvoiceurgeapp. O src/dcvoiceurgeredeal. O src/dcvoiceurgetask. O src/dcvoiceurgeparam. O src/soapc. O src/soapclient. O src/stdsoap2.o-L/public/abp_icc/release/lib-L/ora11g/product/11.2.0/lib-wl,-bstatic-liccengowe
-Liccapiowe-wl,-bdynamic-ldiccpt-locci11-acceleration-lclntsh-lpthread-LRT-lcrypto
A bunch of undefined reference to errors are reported, such:
/Public/abp_icc/release/lib/libiccengowe. So: Undefined reference to 'logcpt: Init (char const *, char const *)'
In fact, this error is often encountered in UNIX, and there is a way to solve it, But the strange thing is that all the symbols written in-ldiccpt are available, there is no problem with the order of packages.

Solution:

We can see that the symbol exists through nm.
/Public/abp_icc/src/public/diccpt/Mak/make_linux> nm libdiccpt. So | grep logcpt | grep init
20171000000034fe6T_ Zn6logcpt4initepkcs1 _
20171000000034f82T_ Zn6logcpt4initev

It is found that the libace. So symbol is obtained. It is strange that the parameters are the same for compilation. How can we use ACE, but we cannot use our own package? In particular, by referring to man lD, we find that the-e parameter requires export all symbol, while we use-WL and-e to carry it, which cannot be solved.
Some attempt was made to use the static library, and it was found that the static library could be used. I carefully checked the symbols of the static library;
20171000000001b36T_ Zn6logcpt4initepkcs1 _
0000000000001ad2T_ Zn6logcpt4initev
It is found that the type in the static library is T and that in the dynamic library is T. after checking the help of nm, we found that the lowercase letter T is the local symbol, while the uppercase letter T is the globle symbol. At this time, the goal is clear, it is to change T in the dynamic library to t...

I finally found the compilation option-fvisibility = hidden-fvisibility-inlines-hidden by referring to the GCC compilation control dynamic library export function summary in Linux, because the ace Code includes the ace_export macro, such code as _ attribute _ (visibility ("default"), but our code is not written like this, eventually, our function symbol does not have export, although the compilation options include-WL and-e.
After removing all the symbols, the export will be available. Check whether the link is too big and there will be no errors.
/Public/abp_icc/release/lib> nm libdiccpt. So | grep logcpt | grep init
20171000000059fd8 T _ zn6logcpt4initepkcs1 _
20171000000059f70 T _ zn6logcpt4initev

Emotion:
1) after several years of C, the details of this compilation option are still a small one;
2) The gap between self-encapsulated components and components provided by third parties is quite large;

3) do not refer to others' compilation parameters unless you fully understand their functions;

4) continuous summary and analysis are required.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.