Find the answer to your Linux question:
Results 1 to 5 of 5
I am doing a little program in c++ using the mp4v2 library, but i have an error. The code is: Code: #include<stdio.h> #include <cstring> #include "mp4.h" using namespace std; char ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2012
    Posts
    3

    Mp4v2 library


    I am doing a little program in c++ using the mp4v2 library, but i have an error.
    The code is:
    Code:
    #include<stdio.h>
    #include <cstring> 
    #include "mp4.h"
    
    using namespace std;
    char *Mp4FileName = "file.mp4";
    
    int main() 
    { 
      	MP4FileHandle  Mp4File;
    	MP4TrackId  Video_track_Id;
    	const char* Video_type;	
      
      	Mp4File = MP4Read(Mp4FileName, 0);
    
     	if (!Mp4File) 
     	{
    		printf("Error");
            	return 0;
     	}
    
     	Video_track_Id = MP4FindTrackId(Mp4File, 0, MP4_VIDEO_TRACK_TYPE, 0);
    
        	if (Video_track_Id == MP4_INVALID_TRACK_ID) 
    	{
            	printf("Track invalid \n");
          	}
        	else 
    	{
            	Video_type = MP4GetTrackMediaDataName(Mp4File, Video_track_Id);
    
            	if (strcmp(Video_type, "mp4v") == 0)
            	   	printf("Video = MPEG4 \n");
        	}
    
     	return 0;
    }
    To compile:
    Code:
    g++ video.cpp -o video
    The error:
    Code:
    /tmp/cc8lcv8e.o: In function `main':
    video.cpp:(.text+0x1a): undefined reference to `MP4Read'
    video.cpp:(.text+0x5c): undefined reference to `MP4FindTrackId'
    video.cpp:(.text+0x89): undefined reference to `MP4GetTrackMediaDataName'
    collect2: error: ld returned 1 exit status
    I put the file mp4.h in the same folder, and the library libmp4v2.so in /lib and /usr/lib.

    I try changed "mp4.h" to <mp4.h> and the error was:
    Code:
    video.cpp:3:17: fatal error: mp4.h: No such file or directory
    compilation terminated.
    Can anyone help me?
    thanks
    Last edited by atreyu; 11-03-2012 at 04:25 AM. Reason: inserted code tags to aid in readability

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Hello and welcome!

    Quote Originally Posted by villarino View Post
    I put the file mp4.h in the same folder, and the library libmp4v2.so in /lib and /usr/lib.
    Have you run ldconfig yet, after putting those files in your lib area? How did you install them in the first place? You really should use your package manager (e.g., yum, apt-get, etc.) to do that. e.g., on my fedora box i do:

    Code:
    yum install libmp4v2-devel
    and that installs, amongst other things:
    Code:
    /usr/include/mp4.h
    /lib/libmp4v2.so
    /lib/libmp4v2.so.0
    after you've run ldconfig (your package manager would probably do this step for you), you should see the lib when you use ldconfig to print what it knows about, e.g.:

    Code:
    # ldconfig -p|grep mp4
            libmp4v2.so.0 (libc6) => /lib/libmp4v2.so.0
    once you've confirmed that's all there, then when you compile, pass the name of the lib (in this case, mp4v2) to the compiler using the "l" flag (that's a lower case L, not a one), so it knows where to get the MP4Read function (et al), e.g.:

    Code:
     g++ -lmp4v2 video.cpp -o video
    If you need more help, post your distro/version info.

  3. #3
    Just Joined!
    Join Date
    Nov 2012
    Posts
    3
    Quote Originally Posted by atreyu View Post
    Hello and welcome!



    Have you run ldconfig yet, after putting those files in your lib area? How did you install them in the first place? You really should use your package manager (e.g., yum, apt-get, etc.) to do that. e.g., on my fedora box i do:

    Code:
    yum install libmp4v2-devel
    and that installs, amongst other things:
    Code:
    /usr/include/mp4.h
    /lib/libmp4v2.so
    /lib/libmp4v2.so.0
    after you've run ldconfig (your package manager would probably do this step for you), you should see the lib when you use ldconfig to print what it knows about, e.g.:

    Code:
    # ldconfig -p|grep mp4
            libmp4v2.so.0 (libc6) => /lib/libmp4v2.so.0
    once you've confirmed that's all there, then when you compile, pass the name of the lib (in this case, mp4v2) to the compiler using the "l" flag (that's a lower case L, not a one), so it knows where to get the MP4Read function (et al), e.g.:

    Code:
     g++ -lmp4v2 video.cpp -o video
    If you need more help, post your distro/version info.




    Thank you for the reply , but the error is the same.

    I had done:
    /usr/inculde/mp4.h
    /lib/libmp4v2.so
    /lib/libmp4v2.so.2

    ldconfig -p|grep mp4
    libmp4v2.so.2 (libc6) => /usr/lib/i386-linux-gnu/libmp4v2.so.2


    g++ -lmp4v2 video.cpp -o video

    /tmp/cc6QKAz4.o: In function `main':
    video.cpp.text+0x1a): undefined reference to `MP4Read'
    video.cpp.text+0x5c): undefined reference to `MP4FindTrackId'
    video.cpp.text+0x89): undefined reference to `MP4GetTrackMediaDataName'

    collect2: error: ld returned 1 exit status

  4. #4
    Just Joined!
    Join Date
    Nov 2012
    Posts
    3

    Solve

    I solved the problem

    To compile: g++ video.cpp -o video -lmp4v2

    Thanks a lot atreyu

  5. #5
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by villarino View Post
    To compile: g++ video.cpp -o video -lmp4v2
    So you had to put the library flag at the end to get it to work? Crazy, it worked for me (on Fedora 17) putting the flag first.

    Anyway, glad you got it sorted. Will mark thread as Solved for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •