Thread: Need a little help setting up gprof based compile

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733

    Need a little help setting up gprof based compile

    I've got as far as this:
    Code:
    make profile=1 debug=1 static_libs=1 rebuild
    ...
    make -f gnu.mak rebuild check=extra
    rm -f src/basic/branch.c.o src/basic/buffer.c.o src/basic/defect.c.o src/basic/encode.c.o src/basic/moment.c.o src/basic/pipefd.c.o src/basic/shared.c.o src/basic/thread.c.o src/basic/vector.c.o src/basic/string/achs.c.o src/basic/string/c16s.c.o src/basic/string/c32s.c.o src/basic/string/tchs.c.o src/basic/string/uchs.c.o src/basic/string/wchs.c.o
    rm -f src/extra/viewfx/shader.c.o src/extra/viewfx/vfxapi.c.o src/extra/viewfx/vfxapp.c.o src/extra/viewfx/vfxbuf.c.o src/extra/viewfx/vfxcfg.c.o src/extra/viewfx/vfxdef.c.o src/extra/viewfx/vfxvar.c.o src/extra/viewfx/vfxwin.c.o
    rm -f src/extra/viewfx/glfw/glfw_api.c.o src/extra/viewfx/glfw/glfw_eio.c.o
    rm -f src/extra/viewfx/gl/opengl_api.c.o src/extra/viewfx/gl/opengl_app.c.o src/extra/viewfx/gl/opengl_def.c.o src/extra/viewfx/gl/opengl_err.c.o src/extra/viewfx/gl/opengl_shader.c.o src/extra/viewfx/gl/opengl_vfxbuf.c.o src/extra/viewfx/gl/opengl_vfxcfg.c.o src/extra/viewfx/gl/opengl_vfxvar.c.o
    rm -f test/basic/main.c.o
    rm -f test/extra/create.c.o test/extra/debug.c.o test/extra/events.c.o test/extra/launch.c.o test/extra/lib.c.o test/extra/main.c.o
    rm -f bin/*basic*.so bin/*extra*.so
    rm -f bin/*basic*.dll bin/*extra*.dll
    rm -f bin/*basic*.out bin/*extra*.out
    rm -f bin/*basic*.elf bin/*extra*.elf
    rm -f bin/*basic*.app bin/*extra*.app
    rm -f bin/*basic*.exe bin/*extra*.exe
    rm -f bin/*basic*.AppImage bin/*extra*.AppImage
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/branch.c.o -c src/basic/branch.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/buffer.c.o -c src/basic/buffer.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/defect.c.o -c src/basic/defect.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/encode.c.o -c src/basic/encode.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/moment.c.o -c src/basic/moment.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/pipefd.c.o -c src/basic/pipefd.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/shared.c.o -c src/basic/shared.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/thread.c.o -c src/basic/thread.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/vector.c.o -c src/basic/vector.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/achs.c.o -c src/basic/string/achs.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/c16s.c.o -c src/basic/string/c16s.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/c32s.c.o -c src/basic/string/c32s.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/tchs.c.o -c src/basic/string/tchs.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/uchs.c.o -c src/basic/string/uchs.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/wchs.c.o -c src/basic/string/wchs.c
    cc -pg -ggdb -Wl,-rpath,.  -fPIC -static -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o bin/libd-p-basic.a
    /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../lib/gcrt1.o: in function `_start':
    (.text+0x24): undefined reference to `main'
    ...
    Compilation failed.
    I'm sure it's a minor fix but I don't see what I did wrong, anyone able to see it?

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Never mind, found out that contrary to what one would expect gcc does not support building static libraries (at least according to the guide I found), I instead have to use an entirely different program:
    Code:
    $(basic_out).a: $(basic_obj_ents)
    	ar rcs $(LIB_PATH)/$@ $^
    Would appreciate being told how to do this with gcc if it is possible, I've yet to find information that suggests I can, also want to do so for *.lib static libs as well, trying to make my project cross-platform and part of that effort is dealt with by using separate extensions to represent different system types (obviously there's *.app/*.out/*.elf/*.AppImage vs *.exe and *.so vs *.dll but I've also been doing *.o vs *.obj trying to get *.a vs *.lib too)

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Compile/Linkage situation is still going hairy:
    Code:
    make profile=1 debug=1 static_libs=1 rebuild
    include ../makefile
    include ../../makefile
    cd ../../ && make rebuild --no-print-directory
    make -f gnu.mak rebuild check=extra
    rm -f src/basic/branch.c.o src/basic/buffer.c.o src/basic/defect.c.o src/basic/encode.c.o src/basic/moment.c.o src/basic/pipefd.c.o src/basic/shared.c.o src/basic/thread.c.o src/basic/vector.c.o src/basic/string/achs.c.o src/basic/string/c16s.c.o src/basic/string/c32s.c.o src/basic/string/tchs.c.o src/basic/string/uchs.c.o src/basic/string/wchs.c.o
    rm -f src/extra/viewfx/shader.c.o src/extra/viewfx/vfxapi.c.o src/extra/viewfx/vfxapp.c.o src/extra/viewfx/vfxbuf.c.o src/extra/viewfx/vfxcfg.c.o src/extra/viewfx/vfxdef.c.o src/extra/viewfx/vfxvar.c.o src/extra/viewfx/vfxwin.c.o
    rm -f src/extra/viewfx/glfw/glfw_api.c.o src/extra/viewfx/glfw/glfw_eio.c.o
    rm -f src/extra/viewfx/gl/opengl_api.c.o src/extra/viewfx/gl/opengl_app.c.o src/extra/viewfx/gl/opengl_def.c.o src/extra/viewfx/gl/opengl_err.c.o src/extra/viewfx/gl/opengl_shader.c.o src/extra/viewfx/gl/opengl_vfxbuf.c.o src/extra/viewfx/gl/opengl_vfxcfg.c.o src/extra/viewfx/gl/opengl_vfxvar.c.o
    rm -f test/basic/main.c.o
    rm -f test/extra/create.c.o test/extra/debug.c.o test/extra/events.c.o test/extra/launch.c.o test/extra/lib.c.o test/extra/main.c.o
    rm -f bin/*basic*.so bin/*extra*.so
    rm -f bin/*basic*.dll bin/*extra*.dll
    rm -f bin/*basic*.out bin/*extra*.out
    rm -f bin/*basic*.elf bin/*extra*.elf
    rm -f bin/*basic*.app bin/*extra*.app
    rm -f bin/*basic*.exe bin/*extra*.exe
    rm -f bin/*basic*.AppImage bin/*extra*.AppImage
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/branch.c.o -r src/basic/branch.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/buffer.c.o -r src/basic/buffer.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/defect.c.o -r src/basic/defect.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/encode.c.o -r src/basic/encode.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/moment.c.o -r src/basic/moment.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/pipefd.c.o -r src/basic/pipefd.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/shared.c.o -r src/basic/shared.c  -l pthread -l dl
    /usr/bin/ld: /tmp/cc3Mku6E.o: in function `openModule':
    /mnt/MEDIA/HOME/gitlab/dragonbuilder/src/basic/shared.c:147: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/thread.c.o -r src/basic/thread.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/vector.c.o -r src/basic/vector.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/achs.c.o -r src/basic/string/achs.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/c16s.c.o -r src/basic/string/c16s.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/c32s.c.o -r src/basic/string/c32s.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/tchs.c.o -r src/basic/string/tchs.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/uchs.c.o -r src/basic/string/uchs.c  -l pthread -l dl
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/basic/string/wchs.c.o -r src/basic/string/wchs.c  -l pthread -l dl
    ar rcs lib/libd-p-basic.a src/basic/branch.c.o src/basic/buffer.c.o src/basic/defect.c.o src/basic/encode.c.o src/basic/moment.c.o src/basic/pipefd.c.o src/basic/shared.c.o src/basic/thread.c.o src/basic/vector.c.o src/basic/string/achs.c.o src/basic/string/c16s.c.o src/basic/string/c32s.c.o src/basic/string/tchs.c.o src/basic/string/uchs.c.o src/basic/string/wchs.c.o
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/extra/viewfx/shader.c.o -r src/extra/viewfx/shader.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/extra/viewfx/vfxapi.c.o -r src/extra/viewfx/vfxapi.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/extra/viewfx/vfxapp.c.o -r src/extra/viewfx/vfxapp.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/extra/viewfx/vfxbuf.c.o -r src/extra/viewfx/vfxbuf.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/extra/viewfx/vfxcfg.c.o -r src/extra/viewfx/vfxcfg.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/extra/viewfx/vfxdef.c.o -r src/extra/viewfx/vfxdef.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/extra/viewfx/vfxvar.c.o -r src/extra/viewfx/vfxvar.c
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/extra/viewfx/vfxwin.c.o -r src/extra/viewfx/vfxwin.c
    ar rcs lib/libd-p-extra.a src/extra/viewfx/shader.c.o src/extra/viewfx/vfxapi.c.o src/extra/viewfx/vfxapp.c.o src/extra/viewfx/vfxbuf.c.o src/extra/viewfx/vfxcfg.c.o src/extra/viewfx/vfxdef.c.o src/extra/viewfx/vfxvar.c.o src/extra/viewfx/vfxwin.c.o
    cc  -pg -D PROFILING -ggdb -D _DEBUG -Wall -Wextra -fPIC  -D BUILD_STATIC_BASIC -D BUILD_STATIC_EXTRA -o src/extra/viewfx/glfw/glfw_api.c.o -r src/extra/viewfx/glfw/glfw_api.c  -l glfw -l GLEW
    /usr/bin/ld: cannot find -lglfw
    /usr/bin/ld: cannot find -lGLEW
    collect2: error: ld returned 1 exit status
    make[2]: *** [src/extra/viewfx/glfw/cfg.mak:19: src/extra/viewfx/glfw/glfw_api.c.o] Error 1
    make[1]: *** [makefile:46: rebuild] Error 2
    make: *** [../../makefile:46: rebuild] Error 2
    Compilation failed.
    Not yet found information that clears up how to sort this out, just in case someone references them in their response, lib*extragl & lib*extraglfw are both supposed to be shared libraries always, however they both rely on functions from lib*extra.a/.so so I would appreciate advise on how to go about producing those shared libraries when lib*extra is static, not dynamic (assuming my current method is wrong, shared.c uses dlopen to link those during runtime so would appreciate advice on how to silence that warning in the log also)

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,110
    Quote Originally Posted by awsdert View Post
    Never mind, found out that contrary to what one would expect gcc does not support building static libraries (at least according to the guide I found), I instead have to use an entirely different program:
    Code:
    $(basic_out).a: $(basic_obj_ents)
    	ar rcs $(LIB_PATH)/$@ $^
    Would appreciate being told how to do this with gcc if it is possible, I've yet to find information that suggests I can, also want to do so for *.lib static libs as well, trying to make my project cross-platform and part of that effort is dealt with by using separate extensions to represent different system types (obviously there's *.app/*.out/*.elf/*.AppImage vs *.exe and *.so vs *.dll but I've also been doing *.o vs *.obj trying to get *.a vs *.lib too)
    Yes, gcc and ar can be used to create static libraries! Hello GOOGLE!

    You use gcc to create the .o files, ar to build the library, and make to drive both.
    Last edited by rstanley; 01-08-2022 at 12:51 PM.

  5. #5
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by rstanley View Post
    Yes, gcc and ar can be used to create static libraries! Hello GOOGLE!

    You use gcc to create the .o files, ar to build the library, and make to drive both.
    1st. Someone seems a bit snippy
    2nd. Given that static libraries are a thing that is exclusive to programming (while media is technically static it's outright weird to say you want to make a static library for media, as if there's such a thing as a dynamic library for media), it is only natural I would expect to have to use the linker to create a static library, it was only by luck (or divine intervention) that I happened come across that information, I had been looking for something else, I was looking for the linker options for making static library since I assumed I must've used the wrong ones.

  6. #6
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,110
    Quote Originally Posted by awsdert View Post
    ... it is only natural I would expect to have to use the linker to create a static library, it was only by luck (or divine intervention) that I happened come across that information, I had been looking for something else, I was looking for the linker options for making static library since I assumed I must've used the wrong ones.
    No, you should not "expect" that. ar, is used to create the static or shared library, ld, the linker, usually called by gcc, is used to link the existing shared or static library to the object files, and startup code to create the executable. ld does not create libraries.

    Long before a carpenter attempts to build a house, he learns that a hammer should not be used to cut a piece of wood, or a saw to hammer a nail.
    Last edited by rstanley; 01-08-2022 at 05:33 PM.

  7. #7
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by rstanley View Post
    No, you should not "expect" that. ar, is used to create the static or shared library, ld, the linker, usually called by gcc, is used to link the existing shared or static library to the object files, and startup code to create the executable. ld does not create libraries.

    Long before a carpenter attempts to build a house, he learns that a hammer should not be used to cut a piece of wood, or a saw to hammer a nail.
    So you're saying by linking objects together the linker is not doing it's job? Right, makes total sense *please note the STRONG sarcasm*

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The reason is that there's no linking involved in creating a static library, since the static library is merely an archive of object files.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by laserlight View Post
    The reason is that there's no linking involved in creating a static library, since the static library is merely an archive of object files.
    I think that would be a case by case basis in terms of type of static library but sure, that at least makes sense, still not the 1st thing a newbie to building static libs would expect, case & point my own thought to use gcc and not some other program that has nothing to do with gcc, rather I now have the question, which came 1st, gcc or ar? or did they both get created with pure asm at the start? either way when dealing with programming objects of any kind the 1st thing one thinks of is the compiler/linker, it's simply not the default expectation to go looking for another program. On a somewhat related note how do *.lib "archives" get created?

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  11. #11

  12. #12
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Finally got the profiling build to actually build & run, albeit with an unfixed segfault, since other people will no doubt find this thread later (or may even be watching this thread for hints on how to fix their own build issues) I'll add a link with the tree, makefile & compiler setup I used (*.lib still not supported directly yet).

    Files * 5632150fdb0838dbaec2035f67678ea0e5008a41 * Lee Shallis / Dragonbuilder * GitLab

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to use gprof
    By mattholm in forum C Programming
    Replies: 5
    Last Post: 12-13-2011, 03:58 PM
  2. Replies: 3
    Last Post: 06-09-2009, 08:16 PM
  3. compiling using gprof
    By shuo in forum C++ Programming
    Replies: 5
    Last Post: 05-27-2008, 07:47 AM
  4. Profiling with GPROF
    By RoshanX in forum C Programming
    Replies: 2
    Last Post: 03-30-2007, 02:38 PM
  5. Setting Up a sector based grid system
    By Auron in forum C Programming
    Replies: 6
    Last Post: 05-20-2005, 08:19 AM

Tags for this Thread