How to link lex.yy.c with main.c by makefile?How do you set, clear, and toggle a single bit?Shell / Makefile LinkerC - C ++ Embed Makefile inside programLinking to thin archive on Snow Leopardcreating a makefileHow to use external libraries and headers in C Makefile?Makefile does not make all targetsLinking with cygwinmakefile: how to generate object files to upper directoryUnderstanding lex.yy.c

What do Unicorns want?

Are Linux kernel modules a sort of Linux system paged pool?

Function pointer parameter without asterisk

What would be the effects of (relatively) widespread precognition on the stock market?

Help!. Wiring an IKEA light fixture into old fixture

Is it better to merge "often" or only after completion do a big merge of feature branches?

What are "the high ends of castles" called?

Source for "everyone has a specific area of Torah that they're naturally drawn to"

What kind of curve (or model) should I fit to my percentage data?

Can I use Sitecore's Configuration patching mechanics for my Identity Server configuration?

Why are Oscar, India, and X-Ray (O, I, and X) not used as taxiway identifiers?

90s (or earlier) book in which a human detective is hired by a vampire to find killer of vampires

How did pilots avoid thunderstorms and related weather before “reliable” airborne weather radar was introduced on airliners?

Recursive search on Node Tree with Linq and Queue

Why was Quirrell said to be in the Black Forest if Voldemort was actually in Albania?

Why did computer video outputs go from digital to analog, then back to digital?

Does switching on an old games console without a cartridge damage it?

Importance of moon phases for Apollo missions

How can I disable a reserved profile?

Why is there an extra "t" in Lemmatization?

Why can't a country print its own money to spend it only abroad?

Counterexample finite intersection property

Stellen - Putting, or putting away?

Found old paper shares of Motorola Inc that has since been broken up



How to link lex.yy.c with main.c by makefile?


How do you set, clear, and toggle a single bit?Shell / Makefile LinkerC - C ++ Embed Makefile inside programLinking to thin archive on Snow Leopardcreating a makefileHow to use external libraries and headers in C Makefile?Makefile does not make all targetsLinking with cygwinmakefile: how to generate object files to upper directoryUnderstanding lex.yy.c






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















In main.c, I call getToken function, which is contained in lex.yy.c generated by flex. I want to compile them by using makefile



CC = gcc
TARGET = lexic

OBJS = util.o main.o

$(TARGET) : lex.yy.c util.o main.o
$(CC) lex.yy.c -ll util.o main.o
util.o : globals.h util.h util.c
$(CC) -c -o util.o util.c
main.o : globals.h util.h main.c
$(CC) -o main.o main.c


I made like this, but the compiler couldn't find where getToken function is.



How can I solve this?










share|improve this question
























  • Don't include your header files in your call to the compiler. Also, use the -c flag when compiling main.c to obtain an object.

    – Thomas Jager
    Mar 26 at 13:37











  • Take a closer look at how you build the main.o file. Are you sure you pass all the correct flags to build an object file? I recommend you learn about implicit rules which will cause make to build object files with the correct flags automatically.

    – Some programmer dude
    Mar 26 at 13:43


















0















In main.c, I call getToken function, which is contained in lex.yy.c generated by flex. I want to compile them by using makefile



CC = gcc
TARGET = lexic

OBJS = util.o main.o

$(TARGET) : lex.yy.c util.o main.o
$(CC) lex.yy.c -ll util.o main.o
util.o : globals.h util.h util.c
$(CC) -c -o util.o util.c
main.o : globals.h util.h main.c
$(CC) -o main.o main.c


I made like this, but the compiler couldn't find where getToken function is.



How can I solve this?










share|improve this question
























  • Don't include your header files in your call to the compiler. Also, use the -c flag when compiling main.c to obtain an object.

    – Thomas Jager
    Mar 26 at 13:37











  • Take a closer look at how you build the main.o file. Are you sure you pass all the correct flags to build an object file? I recommend you learn about implicit rules which will cause make to build object files with the correct flags automatically.

    – Some programmer dude
    Mar 26 at 13:43














0












0








0








In main.c, I call getToken function, which is contained in lex.yy.c generated by flex. I want to compile them by using makefile



CC = gcc
TARGET = lexic

OBJS = util.o main.o

$(TARGET) : lex.yy.c util.o main.o
$(CC) lex.yy.c -ll util.o main.o
util.o : globals.h util.h util.c
$(CC) -c -o util.o util.c
main.o : globals.h util.h main.c
$(CC) -o main.o main.c


I made like this, but the compiler couldn't find where getToken function is.



How can I solve this?










share|improve this question
















In main.c, I call getToken function, which is contained in lex.yy.c generated by flex. I want to compile them by using makefile



CC = gcc
TARGET = lexic

OBJS = util.o main.o

$(TARGET) : lex.yy.c util.o main.o
$(CC) lex.yy.c -ll util.o main.o
util.o : globals.h util.h util.c
$(CC) -c -o util.o util.c
main.o : globals.h util.h main.c
$(CC) -o main.o main.c


I made like this, but the compiler couldn't find where getToken function is.



How can I solve this?







c






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 13:42









Some programmer dude

311k26 gold badges279 silver badges442 bronze badges




311k26 gold badges279 silver badges442 bronze badges










asked Mar 26 at 13:35









uninopknuninopkn

638 bronze badges




638 bronze badges












  • Don't include your header files in your call to the compiler. Also, use the -c flag when compiling main.c to obtain an object.

    – Thomas Jager
    Mar 26 at 13:37











  • Take a closer look at how you build the main.o file. Are you sure you pass all the correct flags to build an object file? I recommend you learn about implicit rules which will cause make to build object files with the correct flags automatically.

    – Some programmer dude
    Mar 26 at 13:43


















  • Don't include your header files in your call to the compiler. Also, use the -c flag when compiling main.c to obtain an object.

    – Thomas Jager
    Mar 26 at 13:37











  • Take a closer look at how you build the main.o file. Are you sure you pass all the correct flags to build an object file? I recommend you learn about implicit rules which will cause make to build object files with the correct flags automatically.

    – Some programmer dude
    Mar 26 at 13:43

















Don't include your header files in your call to the compiler. Also, use the -c flag when compiling main.c to obtain an object.

– Thomas Jager
Mar 26 at 13:37





Don't include your header files in your call to the compiler. Also, use the -c flag when compiling main.c to obtain an object.

– Thomas Jager
Mar 26 at 13:37













Take a closer look at how you build the main.o file. Are you sure you pass all the correct flags to build an object file? I recommend you learn about implicit rules which will cause make to build object files with the correct flags automatically.

– Some programmer dude
Mar 26 at 13:43






Take a closer look at how you build the main.o file. Are you sure you pass all the correct flags to build an object file? I recommend you learn about implicit rules which will cause make to build object files with the correct flags automatically.

– Some programmer dude
Mar 26 at 13:43













1 Answer
1






active

oldest

votes


















0














The problem is that you don't build an object file named main.o, your rule attempt to build an executable by that name.



The simple and most immediate way to solve your problem is to add the -c flag when building:



main.o : globals.h util.h main.c
$(CC) -c -o main.o main.c
# ^^
# Note flag added



A "better" and at least simpler way is to rely on the implicit rules that make have for creating, among other things, object and executable files.



Then you could simply have your Makefile look something like this:



# CFLAGS is the C compiler flags
# Add flags to enable verbose warnings (always a good idea)
CFLAGS = -Wall -Wextra -pedantic

TARGET = lexic

# The libraries to link the target application with
LDLIBS = -ll

# By default the make program uses the first target
default: $(TARGET)

# Because of the implicit rules, make will be able to link the executable by itself
$(TARGET): lex.yy.o util.o main.o

# Also because of implicit rules, object files will be created automatically as well
# But we list them here to specify their header-file dependencies
util.o main.o: globals.h util.h


Important note: The implicit rule for Lex files (including Flex) is to create the source file X.c from the file X.l. So unless your Lex file is names lex.yy.l then you need to change the name of the object file lex.yy.o in the above Makefile.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55358510%2fhow-to-link-lex-yy-c-with-main-c-by-makefile%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The problem is that you don't build an object file named main.o, your rule attempt to build an executable by that name.



    The simple and most immediate way to solve your problem is to add the -c flag when building:



    main.o : globals.h util.h main.c
    $(CC) -c -o main.o main.c
    # ^^
    # Note flag added



    A "better" and at least simpler way is to rely on the implicit rules that make have for creating, among other things, object and executable files.



    Then you could simply have your Makefile look something like this:



    # CFLAGS is the C compiler flags
    # Add flags to enable verbose warnings (always a good idea)
    CFLAGS = -Wall -Wextra -pedantic

    TARGET = lexic

    # The libraries to link the target application with
    LDLIBS = -ll

    # By default the make program uses the first target
    default: $(TARGET)

    # Because of the implicit rules, make will be able to link the executable by itself
    $(TARGET): lex.yy.o util.o main.o

    # Also because of implicit rules, object files will be created automatically as well
    # But we list them here to specify their header-file dependencies
    util.o main.o: globals.h util.h


    Important note: The implicit rule for Lex files (including Flex) is to create the source file X.c from the file X.l. So unless your Lex file is names lex.yy.l then you need to change the name of the object file lex.yy.o in the above Makefile.






    share|improve this answer



























      0














      The problem is that you don't build an object file named main.o, your rule attempt to build an executable by that name.



      The simple and most immediate way to solve your problem is to add the -c flag when building:



      main.o : globals.h util.h main.c
      $(CC) -c -o main.o main.c
      # ^^
      # Note flag added



      A "better" and at least simpler way is to rely on the implicit rules that make have for creating, among other things, object and executable files.



      Then you could simply have your Makefile look something like this:



      # CFLAGS is the C compiler flags
      # Add flags to enable verbose warnings (always a good idea)
      CFLAGS = -Wall -Wextra -pedantic

      TARGET = lexic

      # The libraries to link the target application with
      LDLIBS = -ll

      # By default the make program uses the first target
      default: $(TARGET)

      # Because of the implicit rules, make will be able to link the executable by itself
      $(TARGET): lex.yy.o util.o main.o

      # Also because of implicit rules, object files will be created automatically as well
      # But we list them here to specify their header-file dependencies
      util.o main.o: globals.h util.h


      Important note: The implicit rule for Lex files (including Flex) is to create the source file X.c from the file X.l. So unless your Lex file is names lex.yy.l then you need to change the name of the object file lex.yy.o in the above Makefile.






      share|improve this answer

























        0












        0








        0







        The problem is that you don't build an object file named main.o, your rule attempt to build an executable by that name.



        The simple and most immediate way to solve your problem is to add the -c flag when building:



        main.o : globals.h util.h main.c
        $(CC) -c -o main.o main.c
        # ^^
        # Note flag added



        A "better" and at least simpler way is to rely on the implicit rules that make have for creating, among other things, object and executable files.



        Then you could simply have your Makefile look something like this:



        # CFLAGS is the C compiler flags
        # Add flags to enable verbose warnings (always a good idea)
        CFLAGS = -Wall -Wextra -pedantic

        TARGET = lexic

        # The libraries to link the target application with
        LDLIBS = -ll

        # By default the make program uses the first target
        default: $(TARGET)

        # Because of the implicit rules, make will be able to link the executable by itself
        $(TARGET): lex.yy.o util.o main.o

        # Also because of implicit rules, object files will be created automatically as well
        # But we list them here to specify their header-file dependencies
        util.o main.o: globals.h util.h


        Important note: The implicit rule for Lex files (including Flex) is to create the source file X.c from the file X.l. So unless your Lex file is names lex.yy.l then you need to change the name of the object file lex.yy.o in the above Makefile.






        share|improve this answer













        The problem is that you don't build an object file named main.o, your rule attempt to build an executable by that name.



        The simple and most immediate way to solve your problem is to add the -c flag when building:



        main.o : globals.h util.h main.c
        $(CC) -c -o main.o main.c
        # ^^
        # Note flag added



        A "better" and at least simpler way is to rely on the implicit rules that make have for creating, among other things, object and executable files.



        Then you could simply have your Makefile look something like this:



        # CFLAGS is the C compiler flags
        # Add flags to enable verbose warnings (always a good idea)
        CFLAGS = -Wall -Wextra -pedantic

        TARGET = lexic

        # The libraries to link the target application with
        LDLIBS = -ll

        # By default the make program uses the first target
        default: $(TARGET)

        # Because of the implicit rules, make will be able to link the executable by itself
        $(TARGET): lex.yy.o util.o main.o

        # Also because of implicit rules, object files will be created automatically as well
        # But we list them here to specify their header-file dependencies
        util.o main.o: globals.h util.h


        Important note: The implicit rule for Lex files (including Flex) is to create the source file X.c from the file X.l. So unless your Lex file is names lex.yy.l then you need to change the name of the object file lex.yy.o in the above Makefile.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 13:31









        Some programmer dudeSome programmer dude

        311k26 gold badges279 silver badges442 bronze badges




        311k26 gold badges279 silver badges442 bronze badges


















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55358510%2fhow-to-link-lex-yy-c-with-main-c-by-makefile%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript