Jeff you are absolutely right when you said that the inline keyword only masks the problem. I did earlier the unit tests and invoked the underlying C routines and the app crashed, citing "undefined reference to... "<br>
<br>Now with the new change, I can start testing the code.<br><br>Hai<br><br><div class="gmail_quote">On Wed, Jun 9, 2010 at 12:47 PM, Jeff Newmiller <span dir="ltr"><<a href="mailto:jdnewmil@dcn.davis.ca.us">jdnewmil@dcn.davis.ca.us</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Glad you fixed it okay. After thinking about it for awhile, I think the inline keyword was simply masking the problem. If you had not yet written any code that called new_video_stream, then that method would not be instantiated in your object code, and the offending reference to av_new_stream would not be there needing to be resolved.<br>
<br>
FWIW I recommend not modifying code from the ffmpeg C source to keep your C++ code better isolated from the C code. If you follow this advice you should not need the ifdef at all, because the C compiler should never encounter the extern "C" syntax.<br>
<div><div></div><div class="h5"><br>
"Hai Yi" <<a href="mailto:yihai2004@gmail.com">yihai2004@gmail.com</a>> wrote:<br>
<br>
>thanks Jeff, I wrapped the #include with<br>
><br>
>#ifdef __cplusplus<br>
>extern "C"{<br>
>#endif<br>
><br>
>...<br>
><br>
>#ifdef __cplusplus<br>
>}<br>
>#endif<br>
><br>
>and the inline problem is gone, it's no long needed, the app works like a<br>
>charm!<br>
><br>
>Thought: I did wrap with "extern C{}" before, but I didn't put the<br>
>conditional macro (#ifdef __cplusplus) then as I did it now, guess I used it<br>
>the wrong way then.<br>
><br>
>Thanks again, Hai<br>
><br>
><br>
>On Wed, Jun 9, 2010 at 2:31 AM, Jeff Newmiller <<a href="mailto:jdnewmil@dcn.davis.ca.us">jdnewmil@dcn.davis.ca.us</a>>wrote:<br>
><br>
>> Hai Yi wrote:<br>
>> > Thanks Jeff. However, the header file of those C routines are included<br>
>> > in ffmpegmgr.h, which is in turn included by ffmpegmgr.cpp.<br>
>> ><br>
>> > The "undefined reference " normally indicates that the functions's<br>
>> > definitions are not found, and it takes place when doing the linker.<br>
>><br>
>> I am aware of that. However, if you don't have your calls properly<br>
>> declared<br>
>> then the linking may fail.<br>
>><br>
>> > The<br>
>> > libraries, libavcodec, etc, have been specified from the g++ command<br>
>> > line, and seems to work - only that I need to make the encapulated<br>
>> > member function in ffmpegmgr.cpp inline to eliminate the linker error:<br>
>> ><br>
>> > inline void FFMpegMgr::new_video_stream(AVFormatContext *oc)<br>
>> > {<br>
>> > ...<br>
>> > st = av_new_stream(oc, oc->nb_streams);<br>
>> > ...<br>
>> > }<br>
>><br>
>> I cannot explain that. Adding the inline keyword to new_video_stream<br>
>> eliminates new_video_stream from the linking process (being placed inline,<br>
>> there is no need to link it), but should have no effect on the link-ability<br>
>> of av_new_stream.<br>
>><br>
>> Are you wrapping your C declarations as seen from C++ in extern "C" {}<br>
>> blocks? This is often done by wrapping the #include statement for the C<br>
>> header file in your cpp or C++ header files.<br>
>><br>
>> > Also, the lib that I specified is *.a, will it be different if the lib<br>
>> > is *.so ?<br>
>><br>
>> If you declare your objects correctly, there should be no need for source<br>
>> code changes between static and shared library linking.<br>
>><br>
>> > Thanks,<br>
>> > Hai<br>
>> ><br>
>> ><br>
>> > On Mon, Jun 7, 2010 at 1:26 AM, Jeff Newmiller <<a href="mailto:jdnewmil@dcn.davis.ca.us">jdnewmil@dcn.davis.ca.us</a><br>
>> > <mailto:<a href="mailto:jdnewmil@dcn.davis.ca.us">jdnewmil@dcn.davis.ca.us</a>>> wrote:<br>
>> ><br>
>> > Seems more likely that you haven't included the declarations for the<br>
>> > C routines in your cpp file. Would need to see more context to<br>
>> diagnose.<br>
>> ><br>
>> > "Hai Yi" <<a href="mailto:yihai2004@gmail.com">yihai2004@gmail.com</a> <mailto:<a href="mailto:yihai2004@gmail.com">yihai2004@gmail.com</a>>> wrote:<br>
>> ><br>
>> > >Hello all:<br>
>> > ><br>
>> > >I created a class FFMpegMgr and a method init(); inside init() I<br>
>> > just put<br>
>> > >three ffmpeg api there:<br>
>> > >avcodec_register_all();<br>
>> > >avdevice_register_all();<br>
>> > > av_register_all();<br>
>> > ><br>
>> > >The source file ffmpegmgr.cpp look like this:<br>
>> > ><br>
>> > > void FFMpegMgr::init() {<br>
>> > > avcodec_register_all();<br>
>> > > avdevice_register_all();<br>
>> > > av_register_all();<br>
>> > ><br>
>> > >}<br>
>> > ><br>
>> > >Now I got a "undefined reference to avcodec_register_all" error.<br>
>> > ><br>
>> > >if I put that body in the class declaration or add a "inline"<br>
>> > keyword, that<br>
>> > >problem was gone and the compilation succeeded.<br>
>> > ><br>
>> > >question is, do those three functions, which are C functions<br>
>> > defined in<br>
>> > >avcodec.h, have to be used only in the inline functions in C++?<br>
>> > ><br>
>> > >Sorry if it appear naive - I've been out of touch with C/C++ for a<br>
>> > while.<br>
>> > ><br>
>> > >Thanks!<br>
>> > >Hai<br>
>><br>
>><br>
>> --<br>
>> ---------------------------------------------------------------------------<br>
>> Jeff Newmiller The ..... ..... Go Live...<br>
>> DCN:<<a href="mailto:jdnewmil@dcn.davis.ca.us">jdnewmil@dcn.davis.ca.us</a>> Basics: ##.#. ##.#. Live<br>
>> Go...<br>
>> Live: OO#.. Dead: OO#.. Playing<br>
>> Research Engineer (Solar/Batteries O.O#. #.O#. with<br>
>> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k<br>
>> ---------------------------------------------------------------------------<br>
>> _______________________________________________<br>
>> vox-tech mailing list<br>
>> <a href="mailto:vox-tech@lists.lugod.org">vox-tech@lists.lugod.org</a><br>
>> <a href="http://lists.lugod.org/mailman/listinfo/vox-tech" target="_blank">http://lists.lugod.org/mailman/listinfo/vox-tech</a><br>
>><br>
>_______________________________________________<br>
>vox-tech mailing list<br>
><a href="mailto:vox-tech@lists.lugod.org">vox-tech@lists.lugod.org</a><br>
><a href="http://lists.lugod.org/mailman/listinfo/vox-tech" target="_blank">http://lists.lugod.org/mailman/listinfo/vox-tech</a><br>
<br>
---------------------------------------------------------------------------<br>
Jeff Newmiller The ..... ..... Go Live...<br>
DCN:<<a href="mailto:jdnewmil@dcn.davis.ca.us">jdnewmil@dcn.davis.ca.us</a>> Basics: ##.#. ##.#. Live Go...<br>
Live: OO#.. Dead: OO#.. Playing<br>
Research Engineer (Solar/Batteries O.O#. #.O#. with<br>
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k<br>
---------------------------------------------------------------------------<br>
</div></div><div class="im">Sent from my phone. Please excuse my brevity.<br>
_______________________________________________<br>
</div><div><div></div><div class="h5">vox-tech mailing list<br>
<a href="mailto:vox-tech@lists.lugod.org">vox-tech@lists.lugod.org</a><br>
<a href="http://lists.lugod.org/mailman/listinfo/vox-tech" target="_blank">http://lists.lugod.org/mailman/listinfo/vox-tech</a><br>
</div></div></blockquote></div><br>