Using Dynamic Libraries in C++

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ต.ค. 2017
  • Patreon ► / thecherno
    Twitter ► / thecherno
    Instagram ► / thecherno
    Discord ► thecherno.com/discord
    Series Playlist ► thecherno.com/cpp
    Thank you to the following Patreon supporters:
    - Samuel Egger
    - Dominic Pace
    - Kevin Gregory Agwaze
    - Sébastien Bervoets
    - Tobias Humig
    Gear I use:
    -----------------
    BEST laptop for programming! ► geni.us/pakTES
    My FAVOURITE keyboard for programming! ► geni.us/zNhB
    FAVOURITE monitors for programming! ► geni.us/Ig6KBq
    MAIN Camera ► geni.us/t6xyDRO
    MAIN Lens ► geni.us/xGoDWT
    Second Camera ► geni.us/CYUQ
    Microphone ► geni.us/wqO6g7K

ความคิดเห็น • 185

  • @medvfx3370
    @medvfx3370 6 ปีที่แล้ว +504

    this is literally the meme about programmers that goes
    it's not working, why?
    it's working, why?

    • @TheSpacecraftX
      @TheSpacecraftX 3 ปีที่แล้ว +29

      "The rest is trivial and left as an exercise for the reader."

    • @militardeforcasopostas2559
      @militardeforcasopostas2559 2 ปีที่แล้ว +3

      it's not working?
      other programmers: Too Bad!

  • @mohamedmostafa396
    @mohamedmostafa396 4 ปีที่แล้ว +186

    damn 3 years now and no one answered the question 😂😂

    • @Lelouch-vi-Britania
      @Lelouch-vi-Britania 4 หลายเดือนก่อน +5

      replying you after 3 years few have answers this but noone got pinned lol

  • @user-vf2gt1le4q
    @user-vf2gt1le4q 3 ปีที่แล้ว +102

    If you use lib + dll,you don't need __declspec(dllimport) because all the functions or variables you wan't to import have defined in lib as pointer;but if you use LoadLibary API to import dll, with __declspec(dllimport) you can tell the compiler which function or variable you want to import, it will reduce the import time

  • @muhammadtaimourafzal5285
    @muhammadtaimourafzal5285 3 ปีที่แล้ว +39

    cherno is a blessing for programmer community. awesome tutorial

  • @vertigo6982
    @vertigo6982 5 ปีที่แล้ว +232

    I see no pinned comments.. no one answered it correctly?

    • @NycroLP
      @NycroLP 5 ปีที่แล้ว +39

      I think people did but he doesnt care I guess.

    • @serbastshexany7498
      @serbastshexany7498 4 ปีที่แล้ว

      Am up writing idk perfect English fluently thxs

    • @drisicus
      @drisicus 4 ปีที่แล้ว +10

      ​@@NycroLP I like the content of this channel but the guy is not consistent, he has series unfinished, there is no schedule of videos...
      I mean, he does this because he wants, so ok I guess

    • @bulentgercek
      @bulentgercek 4 ปีที่แล้ว +68

      @@drisicus Are you serious? How is he not consistent? He got 90 videos on this playlist and still keep doing it. Lots of people learned tons of the information from him. If you think you can do better go for it I'll follow you.

    • @gideonmaxmerling204
      @gideonmaxmerling204 3 ปีที่แล้ว +12

      @@bulentgercek bro, this was not meant as an attack towards him and you are being illogical.
      Cherno said he would pin a comment but he didn't, that's all this is about.

  • @crush3dices
    @crush3dices 3 ปีที่แล้ว +45

    Concerning the __declspec(dllimport), if we dont set it the compiler compiles the function call
    glfwInit();
    to something like
    call glfwInit
    inside the object file. The linkers job is to resolve this. If we don't add the __declspec(dllimport) then the linker generates something like
    call 0x4000000
    which directs the flow of the program to a function thunk. A thunk is something like a dummyfunction without ret statement at the end which simply jumps to another address. This thunk could look like
    jmp DWORD PTR __imp_glfwInit
    and the pointer __imp_glfwInit will then be set when the dll is loaded into memory using the IAT to point to the correct function.
    On the other hand, if we set __declspec(dllimport) we explicitly tell the compiler at compiletime that we want to use a function inside a dll. Thus we get the asm code
    call DWORD PTR __imp_glfwInit
    again __imp_glfwInit beeing set at runtime through the IAT. This saves the thunk memory and the jmp instruction.

    • @mohammedjawahri5726
      @mohammedjawahri5726 2 ปีที่แล้ว +2

      nicely explained, cheers

    • @anonymoussloth6687
      @anonymoussloth6687 2 ปีที่แล้ว

      Can u please recommend resources that explore this in more detail?

    • @crush3dices
      @crush3dices 2 ปีที่แล้ว +6

      @@anonymoussloth6687 search for "importing functions using declspec dllimport" inside the microsoft docs

    • @SpecialAgentDaniel
      @SpecialAgentDaniel ปีที่แล้ว

      Thank you for this.

  • @bulentgercek
    @bulentgercek 4 ปีที่แล้ว +32

    8:38 That french throat at "exactly" killed me :D

    • @Gaelrenaultdu06
      @Gaelrenaultdu06 4 หลายเดือนก่อน +5

      I'm french and i have no idea how this is french xD Sounds more arabic.

  • @ksawery6568
    @ksawery6568 4 ปีที่แล้ว +25

    Absolute legend! I kept getting .dll missing errors, and this solved it.

  • @joachimolsson9497
    @joachimolsson9497 6 ปีที่แล้ว +20

    This is because the DLL still has an IAT, Import Address Table. It will still load the functions from the IAT, but as Yuval said if you specify it as import when compiling the compiler will generate imports as imp__func_decl and it will do optimizations to ensure import is efficient.
    However what hasn't been said yet is this is only optional for function declarations so if you use public data members there is no IAT entry for them, and you need dllimport or else the data will be local to the compilation unit or compiling program depending on what other modifiers are used.

    • @anonymoussloth6687
      @anonymoussloth6687 2 ปีที่แล้ว +2

      I am sorry but I have no idea what u said. Can u provide any resources that explains this in detail? Also, any resources that explain linking stuff more

  • @AgentM124
    @AgentM124 6 ปีที่แล้ว +140

    Because you already linked the static library that came with the dll with all the declarations of functions within the dll, it knows where to look for them, except it's maybe slightly less efficient.

    • @yltfy
      @yltfy 4 ปีที่แล้ว +13

      I'm new to this, but I guess this is the right answer.

    • @cprn.
      @cprn. 2 ปีที่แล้ว +5

      Header. He linked and included the library header file. Not the library itself (he did dynamically linked the library itself but it doesn't matter for this answer).

  • @MrBasania
    @MrBasania 5 ปีที่แล้ว +10

    You literally saved me. Thank you for your work!

  • @smileynetsmileynet7922
    @smileynetsmileynet7922 3 ปีที่แล้ว +3

    With MINGW, you can link the standard library statically or dynamicly essentially.

  • @Danlchigo
    @Danlchigo 4 ปีที่แล้ว

    Thanks so much, I tried to install a library but I didn't even know how to do it, but with your help I did it and I learn about it :)

  • @wezo13
    @wezo13 8 หลายเดือนก่อน

    This has been really helpful, thank you

  • @arunkumaran5522
    @arunkumaran5522 6 ปีที่แล้ว +4

    Thanks for the video, most of the videos posted in TH-cam have similar contents. But yours is really interesting and felt I have learnt something new. I am currently try to do something with depth camera, since the technology is something advance its hard to find tutorial online. So, thought of digging deeper into every components of C++ and start doing the project by myself. You saved me!!!! thanks for the help...

  • @leynenslucker2991
    @leynenslucker2991 4 ปีที่แล้ว +7

    I am currently binge watching this and one thing that amazes me: The hair dude. How did he manage to mess up a hair within 10 days????

  • @laad
    @laad 6 ปีที่แล้ว +15

    I was one of those asking for hw/challenges. I'm glad you started doing that!

  • @AmeshaSpentaArmaiti
    @AmeshaSpentaArmaiti 6 ปีที่แล้ว +5

    my guess is because the functions are still defined in the library even though the actual code is in the dll.

  • @mehdinasiri3022
    @mehdinasiri3022 4 ปีที่แล้ว

    thank you very much this movie was very helpful for me

  • @djskippimusic
    @djskippimusic 6 ปีที่แล้ว +3

    Hey Cherno!
    I had a question, I've been trying to figure out. I was curious if you could help c:
    I've been studying the Vulkan API, I dunno if you've looked into it at all; however, the backbone of the API is called the Loader, which you link against when you link Vulkan.
    The Loader is responsible for routing things to the right places, and handling system compatibility. The Loader has different functions for different systems. It can handle processing the functions for you; however, it also gives you the ability to retrieve the function pointer for the appropriate function for that instance, and mapping them to a dispatch table. They do this to mitigate using the Loader as a stage of overhead unless necessary
    I don't expect help with the Vulkan side of things, but I was curious if you could help me fully wrap my head around dispatch tables and function pointers to external libraries.
    I've done some searching and found that you can map functions to values using the std::map. In a situation like this how would you go about populating the appropriate data though? Does it require micromanagement? I feel it's kind of similar to the content in the video, though with Vulkan they added a layer inbetween the library and the application to handle system dependencies.
    I feel this might be something useful to understand in general if it helps with cross compatibility. I appreciate any help you can give c:

  • @junyangliu4812
    @junyangliu4812 ปีที่แล้ว

    I followed the file configuration in your previous video and my .exe file is in the project/bin/Win32/Debug, so I need to paste .dll file into this directory and it worked. Actually many places have the .exe file and only this one work. Thanks!

  • @friedrichwagner8716
    @friedrichwagner8716 2 ปีที่แล้ว +3

    Me: It's not working, why?
    The Cherno: It works, why?
    Todd Howard: It just works!

  • @xMudball12x
    @xMudball12x 3 ปีที่แล้ว +2

    In dynamic linking, the g++ preprocessor gets all the information that the Windows dynamic linker needs to link whatever DLL is needed at runtime. At compile->assemble time, the DLL is only referenced in terms of modification information in the binary information generated by the preprocessor, so the assembler is blind to the DLL itself, until runtime, when the linker finally calls the information it needs from the preprocessor.
    In the static version, the linking step simply happens at the compile time, because the assembler gets all the information it needs from the statically linked file at compile time.
    This is why the dynamic version only works when you tell the preprocessor that it is working with the dynamic linker. Is this correct?

  • @stefh8644
    @stefh8644 2 ปีที่แล้ว

    Great lesson! I did not find the next video for learning how to build a DLL working at Run Time, which one is it?

  • @Xxp0r
    @Xxp0r 6 ปีที่แล้ว +23

    Because you're already linking against a .lib file that has all the pointer definitions defined.

  • @luckyboy20021
    @luckyboy20021 5 ปีที่แล้ว

    Thank a lot

  • @siddharthchauhan1129
    @siddharthchauhan1129 3 ปีที่แล้ว +4

    I never flunked any C++ interview.. (technical + theory) since I started learning C++ from you.
    Design rounds are some other headache though

  • @alisonrae
    @alisonrae 3 ปีที่แล้ว +3

    Previous video: new haircut
    This video: crazy hair
    Me: You are a wizard, Cherno!

  • @themcscripter2111
    @themcscripter2111 2 ปีที่แล้ว

    When you statically link the lib it doesn’t define glfw_dll because it already has all the function declarations for it during compile time. When you define this macro, it still knows where to look for the declarations; inside the dll at run time.

  • @erjuanjojj
    @erjuanjojj 2 ปีที่แล้ว

    Great tutorials! What if I want to put my dll in some subdirectory of my executable, or if I have several search paths with the same dlls and it does not know where to look. Can I tell the executable to link to a specific dll and not other found? Thank you very much

  • @pulkitjoshi6196
    @pulkitjoshi6196 3 ปีที่แล้ว

    so what about instance of the DLL in main memory? Do we have multiple instances of these library in main memory while 2 programs use them ?

  • @themuchcoolman
    @themuchcoolman 6 ปีที่แล้ว

    Defining GLFW_DLL is not necessary because when you call one of the functions in your program it links to the function in the glfw3dll.lib which then links to the function in the glfw3.dll.

  • @fxchesscom
    @fxchesscom 3 ปีที่แล้ว

    Hello Cheom
    Can it possible to package a winform in DLL and export the dll function for third party use? I do it done but error when I use the DLL.
    It's always happen below:
    1.Winform show only when I import dll at the first time.
    2.In third party journal, it always show can't find the function name in dll.
    About a winform in DLL am I right?
    Thank you very much.

  • @masihkhodabandeh508
    @masihkhodabandeh508 3 หลายเดือนก่อน

    Answer to the last question raised in the video: Because we statically load that *dll.lib library which does all things that is necessary for dynamic loading for us.

  • @serbastshexany7498
    @serbastshexany7498 4 ปีที่แล้ว

    Thxs but i can’t understand you without subtitles thxs alot amazing vlog

  • @kgravikumar
    @kgravikumar 6 ปีที่แล้ว +1

    .h file would have __declspec declaration for the library. Is that the reason. Also would have been nicer if you could include the difference in memory size of executables in static and dynamic link library

  • @chainonsmanquants1630
    @chainonsmanquants1630 3 ปีที่แล้ว

    Thanks

  • @amingholizad
    @amingholizad หลายเดือนก่อน

    It is a trick question. It does bot matter if you define it beforehand or not. It is not checking whether it is defined (there is no #ifndef GLFWAPI). It will be redefined in the header file.

  • @koungmeng
    @koungmeng 5 ปีที่แล้ว +16

    My solution of the homework is:
    because we are using static linking, we don't need to use __declspec(dllimport). But if we are using dynamic linking, we might need to use __declspec(dllimport) to let the compiler know that the function is inside the dll file.

    • @starriet
      @starriet ปีที่แล้ว

      It is actually dynamic linking at the end, not static linking, because you need the dll file anyways. Unless you're specifically talking about the lib file accompanied with the dll file.

  • @nayabzsharief6736
    @nayabzsharief6736 5 ปีที่แล้ว

    Hi cherno. Need some help. I have one c++ dll file . I want to use this DLL into c# to create windows form application but when I try to load through add reference I get error. I tried another way by using system.runtime. interopservices in that DLL_import in built function is there but in my DLL I have function which takes one argument as structure member when I call that function it says undefined member ( it is not able to find that structure). So can please provide some solution with example where u have c++ DLL which contains one function and has structure argument

  • @nikoszervo
    @nikoszervo 6 ปีที่แล้ว +1

    Can you make a video about classes (or methods i don't really know) which they use this thing? I don't know what it's purpose is. For example: My_Class_Type *myVar;

    • @TheApoorvagni
      @TheApoorvagni 6 ปีที่แล้ว +1

      Bro, I think you are referring to template programming. He has a video regarding it. search his series.

  • @yogeshpanzade5572
    @yogeshpanzade5572 3 ปีที่แล้ว

    9:00 maybe some how static lib that we link for function declaration define it for us.

  • @whitecola3265
    @whitecola3265 3 ปีที่แล้ว

    I've watched the video "Macros in C++" and I spotted that GLFW_DLL has already been defined in the Preprocessor Definition. Is this the reason?

  • @ahmedtalaat27
    @ahmedtalaat27 2 ปีที่แล้ว

    defining the headers is the reason cause dynamic lib way is using precompiled headers

  • @muhammadshahpaal6325
    @muhammadshahpaal6325 2 ปีที่แล้ว

    My error is that myfilename.dll is missing, try reinstalling (same as yours) but when I place my dll file in debug with exe file of the project it gives me errors about VCRUNTIME and MSVC dll files...why is that?

  • @suyogpathade4805
    @suyogpathade4805 4 ปีที่แล้ว +4

    wht a grt explaination, now I know how's the static and dynamic dll works, now I can die peacefully. :)

  • @altSt0rm
    @altSt0rm 2 ปีที่แล้ว +2

    "Hey, my name's The Cherno and welcome back *CRACK* to my C++ series."

    • @hoen3561
      @hoen3561 2 ปีที่แล้ว

      "Hey my name is the chana and welcome back to my estate plus plus series" XD

  • @eyalpery8470
    @eyalpery8470 4 ปีที่แล้ว

    Good video!

  • @zondaken
    @zondaken 5 ปีที่แล้ว +1

    but how do I do that with the GNU Compilers? the way you show is IDE-based but how is it done when you compile on CLI?

    • @Demki
      @Demki 5 ปีที่แล้ว +4

      If you are using mingw, so g++ (or gcc if you are compiling c), you need to add your include directories with "-I" and include library directories with "-L" and include the actual libraries with "-l".
      This is usually done with a makefile/cmake file to automate the process.
      The same is true if you are compiling with msvc's compiler through the CLI (except the API for specifying directories and libraries is a bit different), or clang (which afaik supports the same argument format as gcc/g++, or provides a binary that supports that argument format)

  • @TheGreatMaverick
    @TheGreatMaverick 4 ปีที่แล้ว

    Nice tutorial! I seem to get it, but in the end, something does not work for me.
    I have a library (namely Armadillo) with library files blas.lib and blas.dll. I supply a path to the library files "-L path/to/libs" and specify I want to use this library file, i.e.: "-lblas". There are two things I have a problem with:
    1. When both files are present in the specified directory, how does compiler know which file (.dll or .lib) must be linked? In other words, how does the compiler distinguish that user wants to perform static or dynamic linking?
    2. When I supply only .lib file, I expect that static linking has been done, so there should be no need for putting .dll library in the solution folder, however, it is not the case and the executable won't run properly.
    I will be glad for any feedback, thanks!

  • @platin2148
    @platin2148 6 ปีที่แล้ว +1

    The question is could i make an application extensible through that mechanism? As i can load arbitrary dlls and runtime.

    • @davidste60
      @davidste60 6 ปีที่แล้ว +2

      Yes, that's how VST plugins work in audio software, you have a folder full of .dll files.

  • @massiveblackwood
    @massiveblackwood 3 ปีที่แล้ว

    Wheres the difference between this and using loadlibrary which you talked about on previous videos? Anyway thanks alot for this series man

  • @jayateerthaguruprasad
    @jayateerthaguruprasad 3 ปีที่แล้ว

    Hey....
    Suppose dll returns STL container such as vector.
    Main gets that vector and assigns to a new vector.
    Both dll and exe compiled using same runtime library ( Multi Threaded Dll or MT) ,my exe crashes.
    But then when I compile using debug versions it works fine .......
    Any idea how to fix this ?
    Basically I want to know how to return STL containers from dll to exe.

  • @ronnoni8301
    @ronnoni8301 5 ปีที่แล้ว +40

    Can you please explain about MakeFiles and their implementations in Visual Studio?

    • @ciankiwi7753
      @ciankiwi7753 3 ปีที่แล้ว +7

      afaik Makefiles are not needed when working in Visual Studio, as VS does that work for you. if you are working with the GNU compiler stuff where you compile your stuff from the command line then a makefile saves you the minutes of typing out commands.

    • @cprn.
      @cprn. 2 ปีที่แล้ว +1

      If you're using VS with a *nix project you'll have to use a converter that takes the Makefile and generates a VS solution/project file for you but it rarely works since Makefiles can (and usually do) contain some arbitrary logic. This makes sense because if you don't need to automate something you'll end up with a pretty basic Makefile that is often not really needed (it'd help if you were editing your code in Notepad or equivalent but fully fetched IDEs often handle "standard" cases for you on-the-fly as in: generate in-memory Makefiles using a link-tables of known libraries and discard those Makefiles after compilation is done - its possible because to decide whether any given source file should be compiled or not it is enough to compare its last modification date with the creation date of its target/output file).

    • @chiragsingla.
      @chiragsingla. 2 ปีที่แล้ว +1

      use cmake to generate makefiles

  • @Ayush_singh_04
    @Ayush_singh_04 3 ปีที่แล้ว +2

    Homework answer: GLFW does not provide any of the API headers .They are provided by your development environment

  • @serkanozturk4217
    @serkanozturk4217 ปีที่แล้ว +1

    Personal Notes:
    - Static linking happens at compile time, dynamic linking happens at runtime (better to learn usage for linux and cmake)

    • @haydarjohn
      @haydarjohn ปีที่แล้ว

      hey bro if you find great make tutorials can you send me too?
      Edit: BTW i watched your target following video. Which company do you work for in turkey if you are working.Just curious.

  • @arthopacini
    @arthopacini 6 ปีที่แล้ว +2

    please, make a tutorial about Setting up the glfw in mac and linux, thanks, your videos are Great!

    • @TeeDawl
      @TeeDawl 6 ปีที่แล้ว +2

      Artho Pacini For Linux just get glfw and glew from your package manager. Then check which libs you need via pkgconfig and simply list them for gcc. Then you're done.

    • @peterarbeitsloser7819
      @peterarbeitsloser7819 3 ปีที่แล้ว +1

      @@TeeDawl do you have a tutorial link or something?

  • @santoshs4393
    @santoshs4393 3 ปีที่แล้ว

    Please make a video on how to use c# library in a C++ library or C++ application.

  • @Ayush_singh_04
    @Ayush_singh_04 3 ปีที่แล้ว +2

    Homework answer: we know that we have putted the dll in the folder that's why we don't need to define gflws_api

  • @dex6596
    @dex6596 6 ปีที่แล้ว

    Is there any way how to make Visual Studio copy dlls to output directory automaticaly?

    • @agfd5659
      @agfd5659 6 ปีที่แล้ว

      DEXIT yes

  • @tzgardner
    @tzgardner ปีที่แล้ว

    8:00 It's not clear to me why you would have if else statements for dllexport and dllimport in the same file. If you are using particular code to build a dll (hence using dllexport), how and why would you ever use dllimport here?

  • @xristosbart8217
    @xristosbart8217 6 ปีที่แล้ว +1

    The dll.lib file did that declspec

  • @nrgamepoint3132
    @nrgamepoint3132 3 ปีที่แล้ว

    May be that macros are included in that glf header file.😁

  • @jousboxx9532
    @jousboxx9532 4 ปีที่แล้ว

    What's the music?

  • @pramodbhandari9151
    @pramodbhandari9151 4 ปีที่แล้ว

    You did define GLFW_DLL but you didn't add any reference to it so it really doesn't matter, the pointers from static dll library file are still the ones doing the job and thus nothing changes.

  • @arunabhbhattacharya5314
    @arunabhbhattacharya5314 ปีที่แล้ว

    We do not need to use __declspec(dllimport) to link to the GLFW functions in a DLL file because the necessary import/export attributes are already included in the GLFW header files and source code.

    • @sephirapple7317
      @sephirapple7317 10 หลายเดือนก่อน +1

      @arunabhbhattacharya5314 that's not quite correct. the GLFW header file does not contain all the necessary information to link to the DLL file alone. Although it does define GLFWAPI as __declspec(dllimport), this will only happen if GLFW_DLL has already been defined, else __declspec(dllimport) will not be selected from the #ifdef block!
      All the function pointers in the header are prefixed with GLFWAPI, which the preprocessor has to interpret based on the #ifdef block conditions
      If GLFW_DLL is NOT defined, then GLFWAPI is NOT interpreted as __declspec(dllimport)! Or, for example, if GLFW_BUILD_DLL is defined instead, then GLFWAPI becomes __declspec(dllexport) instead!
      We do not need to put __declspec(dllimport) in front of every function pointer in the header file, because GLFWAPI becomes __declspec(dllimport) when GLFW_DLL is defined!
      The real question however, is why do we not need to define GLFW_DLL to let the preprocessor know how to interpret GLFWAPI?? In other words, where is #define GLFW_DLL written so that we did not need to define it ourselves?
      And the answer is, as other people have said, GLFW_DLL is defined in glfw3.dll.lib, the static library which pairs with glfw3.dll, the dynamic library!
      This is why we do not have to #define GLFW_DLL in the project properties, because it is already in glfw3.dll.lib and therefore when the preprocessor reads the header and gets to the #ifdef for GLFWAPI, then it chooses to interpret any GLFWAPI prefix in the rest of the file as __declspec(dllimport) without us manually defining GLFW_DLL.
      Hope this helps to understand what is happening here!

  • @cipsasmiaumiau3773
    @cipsasmiaumiau3773 5 หลายเดือนก่อน

    hello, I have a question, why are most people not using namespace std? Is this just preference or are there other benefits to it.

    • @CSDex
      @CSDex หลายเดือนก่อน

      It’s bad practice

    • @cipsasmiaumiau3773
      @cipsasmiaumiau3773 หลายเดือนก่อน

      @@CSDex Yes, I understand that, but what is the reason for it? Why is it bad practice?

  • @sparklexscrewyachivements813
    @sparklexscrewyachivements813 3 ปีที่แล้ว

    coool

  • @stephenfreel899
    @stephenfreel899 ปีที่แล้ว

    all i want to know is if he ever plays the guitars in the background of these videos

  • @user-qg8hi2th6k
    @user-qg8hi2th6k 4 ปีที่แล้ว

    I have commented out the GLFWAPI's declaration but keep the"#define GLFWAPI",it still prints 1.

  • @VincenzoR97
    @VincenzoR97 4 ปีที่แล้ว

    that moment when 5:16
    you shouldn't tell people they can't make it.
    tell us what could go wrong and what we can do to not make it go wrong

  • @naserhamidi6386
    @naserhamidi6386 3 ปีที่แล้ว

    challenge answer: With that, it is now static linking

  • @bloodwolf8307
    @bloodwolf8307 4 ปีที่แล้ว

    cool

  • @dariomylonopoulos8462
    @dariomylonopoulos8462 6 ปีที่แล้ว +1

    The static library glfw3dll.lib takes care of importing the dll data for you, if you didn't link that static library you would need to define GLFW_DLL, and would be able to use just the dynamic library glfw3.dll

    • @yuvalgamzon-kapeller5585
      @yuvalgamzon-kapeller5585 6 ปีที่แล้ว +3

      Dario Mylonopoulos, actually if you didn't use the static library you would need to do a lot more. You would need to call LoadLibrary to load the dll and then call GetProcAddress to get pointers to functions from the dll. This is essentially what GLEW does. It loads functions from the driver's dll

  • @danielkrajnik3817
    @danielkrajnik3817 3 ปีที่แล้ว

    8:00 captions on

  • @michaliskaseris2467
    @michaliskaseris2467 4 ปีที่แล้ว +1

    Because the _WIN32 and GFLW_DLL are now both defined, the elif defined(_WIN32) && defined(GLFW_DLL) evaluates to true. Consequently, GLFWAPI evaluates to __declspec(dllimport).

    • @fr3ddyfr3sh
      @fr3ddyfr3sh 4 ปีที่แล้ว +1

      Michalis Kaseris this is the correct answer!

  • @byronwatkins2565
    @byronwatkins2565 4 ปีที่แล้ว

    You are still linking to the glfwdll.lib library of stubs...

  • @kontent_king
    @kontent_king 5 ปีที่แล้ว +2

    Plz make a video on C++ SQL Connector.

  • @kuroakevizago
    @kuroakevizago 3 ปีที่แล้ว

    Please put the answer Cherno really need it :)

  • @RK-on1br
    @RK-on1br 5 ปีที่แล้ว

    yeah, exachktly

  • @boot-strapper
    @boot-strapper 6 ปีที่แล้ว +3

    How do you do linking without a fancy IDE? I prefer command line and simple text editors. Most other languages have configs files for this kind of thing, what about C++?

    • @TheCherno
      @TheCherno  6 ปีที่แล้ว +7

      You should really get used to using an IDE man, you might be okay on small projects but once you get to working on anything of decent size you won't be able to do it. That being said for MSVC look at the cl.exe command line flags: msdn.microsoft.com/en-us/library/f35ctcxw.aspx

    • @boot-strapper
      @boot-strapper 6 ปีที่แล้ว +2

      I find that using IDEs leads people to not actually understand how the code all fits together. I do use intelliJ at work sometimes but I really prefer sublime text and the good ol' command line. Plus I use linux generally which has limited support for Microsoft products and IDEs.
      I've been attempting to use your lessons to build a game that I can compile to web assembly and run in the browser. Keep up the good work man, loving it!

    • @mattstone7670
      @mattstone7670 6 ปีที่แล้ว

      @Kishore G. I've been using Emacs for school, and visual studio for anything I do as personal projects. I feel like emacs is such a pain to use (probably just inexperience), but it is much better than vim IMO. However, some of the most basic features seem to be missing (like going to the definition of a function). How do you enable that at work? Or do you end up just using grep all of the time? I had some luck using gtags and hitting m-., but half of the time it takes me to the wrong definition.

    • @Demki
      @Demki 5 ปีที่แล้ว

      I know it's a bit of a late reply but...
      Generally the way to go about it if you don't want to use an IDE is to use make/cmake to automate the compilation. FWIW if you are using Visual Studio you can enable a more verbose build output which shows you the exact CLI commands used to build the solution. (Tools -> Options... -> Projects and Solutions -> Build and Run: set "MSBuild project build verbosity:" to "Detailed" or "Diagnostic", or if you prefer the log file - set the "MSBuild project build log file verbosity:" to "Detailed" or "Diagnostic").
      If you are using GCC/G++ or clang then the command line arguments format are a bit different from MSVC's, but overall require the same stuff (specifying include directories, specifying library directories, specifying libraries).
      At that point you are better off making a makefile for any project that is a bit larger, which will allow you to automate the build process (you'd only have to type "make" in the command line to build the project).
      Basically an IDE makes the process of making a makefile easier (in fact visual studio uses a slightly different form equivalent to makefiles in its project files, but overall it achieves the same goal).

  • @mikefochtman7164
    @mikefochtman7164 ปีที่แล้ว

    I'd just add a small comment. The second time you compiled your DLL, you didn't copy the new version over to where the .exe file lives. That means the second time you ran it, your exe used the older version of your dll. Moving the DLL should be made part of the build automatically with a custom build step.
    Someone new to DLL's can get frustrated when they make a change to the DLL code, hit 'Build All', and their change doesn't seem to work. Manually copying the DLL outside of VS means VS doesn't know how to update that copy. (go ahead, ask me how I learned this... lol )

  • @abacaabaca8131
    @abacaabaca8131 3 หลายเดือนก่อน

    Does anyone knows how to do this using g++.
    The AI i am consulting to atm does not tell anything about macro definition in the source code.
    I have three source files:
    1. vec2d.cp
    2. triangle.cpp
    3. zone.cpp
    triangle.cpp depends on vec2d.cpp and zone.cpp depends on triangle.cpp and vec2d.cpp.
    My strategy:
    1. compile all .cpp files into .o file
    command:
    Example:
    g++ -c vec2d.cpp -o vec2d.o
    g++ -c triangle.cpp -o triangle.o
    g++ -c zone.cpp -o zone.o
    2. link the object files when there is usage into a single .dll file.
    g++ vec2d.o triangle.o zone.o -o zone.dll
    Cannot remember whether this is the command. Objectively, we want zone.dll
    3. Write a consumer code
    that depends on zone.dll by including its respective .h files.
    for example,
    #include "zone.h"
    4. compile the consumer code into .o file
    g++ -c consumer.cpp -o consumer.o
    5. Link consumer.o to zone.dll
    g++ consumer.o -L. -l:zone -o program
    */Unfortunately i got linker error exception at this point because it cannot find zone.dll in the linker's search path.

  • @susobhandas6143
    @susobhandas6143 3 ปีที่แล้ว

    hey cherno bro -

  • @gawarivivek
    @gawarivivek 3 ปีที่แล้ว

    Because we have included "glfw3.h".

  • @miguelhyto54
    @miguelhyto54 3 ปีที่แล้ว

    8:45 idk men D: i came here to learn :v

  • @jakubpruher979
    @jakubpruher979 5 ปีที่แล้ว +1

    What the hell is __declspec? I'm looking it up now, but damn! Might have said it, since this is a TUTORIAL!

  • @Kramer-tt32
    @Kramer-tt32 11 หลายเดือนก่อน

    I thought libraries had .so or .a files. What the heck is all this!?!... I'm so glad I use linux at my job every day

    • @docika86
      @docika86 7 หลายเดือนก่อน

      What you have mentioned is the Unix/Linux analogies of dynamic( .so = shared object) and static library( .a - archive) file type extensions. This video above concerns the Windows related terminology(hence the author created and maintains a Win. video game engine and this tutorial series is connected to that).

  • @arungaurav7054
    @arungaurav7054 3 ปีที่แล้ว

    where is the pinned comment?

  • @ahmedtalaat27
    @ahmedtalaat27 2 ปีที่แล้ว

    static linking uses ..lib + headers and more optimized way | dynamic linking uses ...dll.lib + ... .dll files but not optimized.

  • @johnlime1469
    @johnlime1469 4 ปีที่แล้ว +6

    I think I watched too many Chris Hansen videos because I keep hearing "pedophiles" instead of "header files"

  • @Ochenter
    @Ochenter 4 ปีที่แล้ว

    Do I need a PC to do these lessons ?
    Thanks.

    • @Ochenter
      @Ochenter 4 ปีที่แล้ว +1

      @Tintin Hello.
      Are you the real "Tintin" ?
      What is a mobile ? Thanks.

  • @alexreg78
    @alexreg78 ปีที่แล้ว

    We touch item$
    Time...
    So.. Be course
    We r not
    Alone. Alien...

  • @user-si9jy3zs1j
    @user-si9jy3zs1j 3 ปีที่แล้ว

    no one answered the question, after 3 years :(.
    What's the secret anyway?

  • @user-iu9ph5ld2v
    @user-iu9ph5ld2v ปีที่แล้ว

    I even do not understand the question....

  • @johnclasing4627
    @johnclasing4627 2 ปีที่แล้ว

    Where's the pinned comment!?

  • @donaldoguio6273
    @donaldoguio6273 6 ปีที่แล้ว

    Man I have a problem with that:
    Diseñar un programa en Visual C++ que calcule el salario a pagar a un obrero que trabaja
    X días con Y horas extras diurnas, sabiendo que el salario mensual es de N pesos (205
    horas) y que el valor de la hora extra se incrementa en un 25% del valor de la hora diaria.
    Los datos se ingresan por teclado.
    please help with that. :)

    • @sablanex
      @sablanex 6 ปีที่แล้ว +1

      donaldo guio Good luck, next time try English.

    • @mariogalindoq
      @mariogalindoq 6 ปีที่แล้ว

      You don't know nothing about programming, but even worst, you don't know nothing about English. I think you are in a serious problem. I recommend you to start learning how to use google translator. This time I'll do that for you:
      Tu no sabes nada de programación, pero aun peor, no sabes nada de inglés. Creo que estás en un problema muy serio. Te recomiendo que empieces por aprender como usar el traductor de google. Esta vez hice la traducción por ti.

  • @Garycarlyle
    @Garycarlyle 4 ปีที่แล้ว

    Good video but would have preferred not to have to do homework. I didnt even do it in high school :)

    • @Garycarlyle
      @Garycarlyle 4 ปีที่แล้ว

      Probably can tell by my bad written English LOL

  • @kemptcode
    @kemptcode 6 ปีที่แล้ว +21

    I wish I spoke australian.

    • @TutorialsWithGary
      @TutorialsWithGary 6 ปีที่แล้ว

      John Doe î

    • @Gizego
      @Gizego 6 ปีที่แล้ว +7

      English is 2nd language for me and i have no problem understanding

    • @LousyPainter
      @LousyPainter 6 ปีที่แล้ว

      He was kidding... At least I hope he was.

    • @fatihakbas8529
      @fatihakbas8529 6 ปีที่แล้ว +2

      Why? Are you going to make some tutorials in English using Australian accent?

    • @vertigo6982
      @vertigo6982 5 ปีที่แล้ว

      The only Australian I know is "Fosters" is Australian for "beer".

  • @alexreg78
    @alexreg78 ปีที่แล้ว

    Lord) cash memory
    Free?
    U freak))