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

            How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

            Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?