0

I started using SDL last week and was always trying to install it. However, I can never compile my code correctly.

I use MinGW i686 for my compiler and I use vim82. Also, I compile C++ code in command line on Windows 10. The SDL version is SDL_2.0.22. I am sure that I copied i686 folder during SDL installation. So what's the problem?

Here's my code:

#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>

#include <iostream>

int main(int argc, int **argv) {

    if (SDL_Init(SDL_INIT_EVERYTHING)) {
        std::cout << "SDL failed to initialize." << std::endl;
    }
    
    return 0;
}

Here's my compilation command and my compilation log(Ignore my grammar mistakes plz):

D:\Coding\C++\WindowApplications\SDLTutorial>g++ main.cpp -o main
C:\Users\joshu\AppData\Local\Temp\ccaMatJ9.o:main.cpp:(.text+0x1e): undefined reference to `SDL_Init'
collect2.exe: error: ld returned 1 exit status

That just doesn't make sense. I copied exactly every step on youtube, SDL official website etc. Also, my PATH settings are all User setting, not System. That's because I don't have ADMIN-RIGHTS.

The code below is my tree in MinGW(or sth.)

D:.
├───bin
├───include
│   ├───ddk
│   ├───gdiplus
│   ├───GL
│   ├───libltdl
│   ├───parts
│   ├───SDL2
│   └───sys
├───lib
│   ├───cmake
│   │   └───SDL2
│   ├───gcc
│   │   └───mingw32
│   │       └───6.3.0
│   │           ├───adainclude
│   │           ├───adalib
│   │           ├───debug
│   │           ├───finclude
│   │           ├───include
│   │           │   ├───c++
│   │           │   │   ├───backward
│   │           │   │   ├───bits
│   │           │   │   ├───debug
│   │           │   │   ├───decimal
│   │           │   │   ├───experimental
│   │           │   │   │   └───bits
│   │           │   │   ├───ext
│   │           │   │   │   └───pb_ds
│   │           │   │   │       └───detail
│   │           │   │   │           ├───binary_heap_
│   │           │   │   │           ├───binomial_heap_
│   │           │   │   │           ├───binomial_heap_base_
│   │           │   │   │           ├───bin_search_tree_
│   │           │   │   │           ├───branch_policy
│   │           │   │   │           ├───cc_hash_table_map_
│   │           │   │   │           ├───eq_fn
│   │           │   │   │           ├───gp_hash_table_map_
│   │           │   │   │           ├───hash_fn
│   │           │   │   │           ├───left_child_next_sibling_heap_
│   │           │   │   │           ├───list_update_map_
│   │           │   │   │           ├───list_update_policy
│   │           │   │   │           ├───ov_tree_map_
│   │           │   │   │           ├───pairing_heap_
│   │           │   │   │           ├───pat_trie_
│   │           │   │   │           ├───rb_tree_map_
│   │           │   │   │           ├───rc_binomial_heap_
│   │           │   │   │           ├───resize_policy
│   │           │   │   │           ├───splay_tree_
│   │           │   │   │           ├───thin_heap_
│   │           │   │   │           ├───tree_policy
│   │           │   │   │           ├───trie_policy
│   │           │   │   │           └───unordered_iterator
│   │           │   │   ├───mingw32
│   │           │   │   │   ├───bits
│   │           │   │   │   └───ext
│   │           │   │   ├───parallel
│   │           │   │   ├───profile
│   │           │   │   │   └───impl
│   │           │   │   ├───tr1
│   │           │   │   └───tr2
│   │           │   ├───objc
│   │           │   └───ssp
│   │           └───include-fixed
│   ├───gettext
│   └───pkgconfig
├───libexec
│   ├───gcc
│   │   └───mingw32
│   │       └───6.3.0
│   │           └───install-tools
│   └───mingw-get
├───mingw32
│   ├───bin
│   ├───include
│   └───lib
│       └───ldscripts
├───msys
│   └───1.0
│       ├───bin
│       ├───etc
│       │   └───ssh
│       ├───include
│       ├───lib
│       │   ├───openssl
│       │   │   └───engines-1.0.0
│       │   └───perl5
│       │       ├───5.8
│       │       │   ├───Attribute
│       │       │   ├───auto
│       │       │   │   └───POSIX
│       │       │   │       └───SigAction
│       │       │   ├───B
│       │       │   ├───Carp
│       │       │   ├───CGI
│       │       │   │   └───eg
│       │       │   ├───Class
│       │       │   ├───CPAN
│       │       │   ├───DBM_Filter
│       │       │   ├───Devel
│       │       │   ├───Digest
│       │       │   ├───Encode
│       │       │   │   ├───CN
│       │       │   │   ├───JP
│       │       │   │   ├───KR
│       │       │   │   ├───MIME
│       │       │   │   │   └───Header
│       │       │   │   └───Unicode
│       │       │   ├───Exporter
│       │       │   ├───ExtUtils
│       │       │   │   ├───Command
│       │       │   │   ├───Constant
│       │       │   │   ├───Liblist
│       │       │   │   └───MakeMaker
│       │       │   ├───File
│       │       │   │   └───Spec
│       │       │   ├───Filter
│       │       │   ├───Getopt
│       │       │   ├───Hash
│       │       │   ├───I18N
│       │       │   │   └───LangTags
│       │       │   ├───IO
│       │       │   │   └───Socket
│       │       │   ├───IPC
│       │       │   ├───List
│       │       │   ├───Locale
│       │       │   │   └───Maketext
│       │       │   ├───Math
│       │       │   │   ├───BigFloat
│       │       │   │   └───BigInt
│       │       │   ├───Memoize
│       │       │   ├───msys
│       │       │   │   ├───auto
│       │       │   │   │   ├───attrs
│       │       │   │   │   ├───B
│       │       │   │   │   │   └───C
│       │       │   │   │   ├───ByteLoader
│       │       │   │   │   ├───Cwd
│       │       │   │   │   ├───Data
│       │       │   │   │   │   └───Dumper
│       │       │   │   │   ├───Devel
│       │       │   │   │   │   ├───DProf
│       │       │   │   │   │   ├───Peek
│       │       │   │   │   │   └───PPPort
│       │       │   │   │   ├───Digest
│       │       │   │   │   │   └───MD5
│       │       │   │   │   ├───DynaLoader
│       │       │   │   │   ├───Encode
│       │       │   │   │   │   ├───Byte
│       │       │   │   │   │   ├───CN
│       │       │   │   │   │   ├───EBCDIC
│       │       │   │   │   │   ├───JP
│       │       │   │   │   │   ├───KR
│       │       │   │   │   │   ├───Symbol
│       │       │   │   │   │   ├───TW
│       │       │   │   │   │   └───Unicode
│       │       │   │   │   ├───Fcntl
│       │       │   │   │   ├───File
│       │       │   │   │   │   └───Glob
│       │       │   │   │   ├───Filter
│       │       │   │   │   │   └───Util
│       │       │   │   │   │       └───Call
│       │       │   │   │   ├───GDBM_File
│       │       │   │   │   ├───IO
│       │       │   │   │   ├───List
│       │       │   │   │   │   └───Util
│       │       │   │   │   ├───MIME
│       │       │   │   │   │   └───Base64
│       │       │   │   │   ├───NDBM_File
│       │       │   │   │   ├───ODBM_File
│       │       │   │   │   ├───Opcode
│       │       │   │   │   ├───PerlIO
│       │       │   │   │   │   ├───encoding
│       │       │   │   │   │   ├───scalar
│       │       │   │   │   │   └───via
│       │       │   │   │   ├───POSIX
│       │       │   │   │   ├───re
│       │       │   │   │   ├───sdbm
│       │       │   │   │   ├───SDBM_File
│       │       │   │   │   ├───Socket
│       │       │   │   │   ├───Storable
│       │       │   │   │   ├───Sys
│       │       │   │   │   │   ├───Hostname
│       │       │   │   │   │   └───Syslog
│       │       │   │   │   ├───threads
│       │       │   │   │   │   └───shared
│       │       │   │   │   ├───Time
│       │       │   │   │   │   └───HiRes
│       │       │   │   │   ├───Unicode
│       │       │   │   │   │   └───Normalize
│       │       │   │   │   ├───Win32CORE
│       │       │   │   │   └───XS
│       │       │   │   │       ├───APItest
│       │       │   │   │       └───Typemap
│       │       │   │   ├───B
│       │       │   │   ├───CORE
│       │       │   │   ├───Data
│       │       │   │   ├───Devel
│       │       │   │   ├───Digest
│       │       │   │   ├───Encode
│       │       │   │   ├───File
│       │       │   │   ├───Filter
│       │       │   │   │   └───Util
│       │       │   │   ├───IO
│       │       │   │   ├───MIME
│       │       │   │   ├───PerlIO
│       │       │   │   ├───Sys
│       │       │   │   ├───threads
│       │       │   │   ├───Time
│       │       │   │   ├───Unicode
│       │       │   │   └───XS
│       │       │   ├───Net
│       │       │   │   └───FTP
│       │       │   ├───PerlIO
│       │       │   │   └───via
│       │       │   ├───Pod
│       │       │   │   ├───Perldoc
│       │       │   │   └───Text
│       │       │   ├───pods
│       │       │   ├───Scalar
│       │       │   ├───Search
│       │       │   ├───Term
│       │       │   ├───Test
│       │       │   │   ├───Builder
│       │       │   │   │   └───Tester
│       │       │   │   └───Harness
│       │       │   ├───Text
│       │       │   ├───Thread
│       │       │   ├───Tie
│       │       │   ├───Time
│       │       │   ├───Unicode
│       │       │   │   └───Collate
│       │       │   ├───unicore
│       │       │   │   ├───lib
│       │       │   │   │   ├───bc
│       │       │   │   │   ├───ccc
│       │       │   │   │   ├───dt
│       │       │   │   │   ├───ea
│       │       │   │   │   ├───gc_sc
│       │       │   │   │   ├───hst
│       │       │   │   │   ├───jt
│       │       │   │   │   ├───lb
│       │       │   │   │   └───nt
│       │       │   │   └───To
│       │       │   ├───User
│       │       │   └───warnings
│       │       ├───site_perl
│       │       │   └───5.8
│       │       └───vendor_perl
│       │           └───5.8
│       │               ├───Archive
│       │               │   ├───Tar
│       │               │   └───Zip
│       │               ├───auto
│       │               │   ├───Compress
│       │               │   │   └───Zlib
│       │               │   └───Tee
│       │               ├───Bundle
│       │               ├───Compress
│       │               ├───Config
│       │               ├───CPAN
│       │               │   ├───Kwalify
│       │               │   └───Reporter
│       │               ├───Devel
│       │               │   └───Symdump
│       │               ├───ExtUtils
│       │               │   └───CBuilder
│       │               │       └───Platform
│       │               ├───File
│       │               │   ├───Copy
│       │               │   └───HomeDir
│       │               ├───HTML
│       │               ├───HTTP
│       │               │   ├───Cookies
│       │               │   ├───Headers
│       │               │   └───Request
│       │               ├───IO
│       │               │   ├───Compress
│       │               │   │   ├───Adapter
│       │               │   │   ├───Base
│       │               │   │   ├───Gzip
│       │               │   │   ├───Zip
│       │               │   │   └───Zlib
│       │               │   └───Uncompress
│       │               │       └───Adapter
│       │               ├───IPC
│       │               │   └───Run3
│       │               ├───LWP
│       │               │   ├───Authen
│       │               │   └───Protocol
│       │               ├───Module
│       │               │   ├───Build
│       │               │   │   └───Platform
│       │               │   └───ScanDeps
│       │               ├───msys
│       │               │   ├───auto
│       │               │   │   ├───Alias
│       │               │   │   ├───Archive
│       │               │   │   │   ├───Tar
│       │               │   │   │   └───Zip
│       │               │   │   ├───B
│       │               │   │   │   └───Generate
│       │               │   │   ├───Compress
│       │               │   │   │   ├───Bzip2
│       │               │   │   │   ├───Raw
│       │               │   │   │   │   ├───Bzip2
│       │               │   │   │   │   └───Zlib
│       │               │   │   │   └───Zlib
│       │               │   │   ├───Config
│       │               │   │   │   └───Tiny
│       │               │   │   ├───CPAN
│       │               │   │   │   └───Reporter
│       │               │   │   ├───Devel
│       │               │   │   │   └───Symdump
│       │               │   │   ├───Digest
│       │               │   │   │   └───SHA
│       │               │   │   ├───ExtUtils
│       │               │   │   │   ├───CBuilder
│       │               │   │   │   └───ParseXS
│       │               │   │   ├───File
│       │               │   │   │   ├───Copy
│       │               │   │   │   │   └───Recursive
│       │               │   │   │   ├───HomeDir
│       │               │   │   │   ├───pushd
│       │               │   │   │   └───Temp
│       │               │   │   ├───HTML
│       │               │   │   │   ├───Parser
│       │               │   │   │   └───Tagset
│       │               │   │   ├───IO
│       │               │   │   │   ├───CaptureOutput
│       │               │   │   │   ├───Compress
│       │               │   │   │   │   ├───Base
│       │               │   │   │   │   ├───Bzip2
│       │               │   │   │   │   └───Zlib
│       │               │   │   │   ├───String
│       │               │   │   │   └───Zlib
│       │               │   │   ├───IPC
│       │               │   │   │   └───Run3
│       │               │   │   ├───LWP
│       │               │   │   ├───Math
│       │               │   │   │   └───BigInt
│       │               │   │   │       └───FastCalc
│       │               │   │   ├───MD5
│       │               │   │   ├───Module
│       │               │   │   │   ├───Build
│       │               │   │   │   └───ScanDeps
│       │               │   │   ├───Net
│       │               │   │   │   └───Telnet
│       │               │   │   ├───PadWalker
│       │               │   │   ├───PAR
│       │               │   │   │   └───Dist
│       │               │   │   ├───Pod
│       │               │   │   │   ├───Coverage
│       │               │   │   │   ├───Escapes
│       │               │   │   │   ├───Readme
│       │               │   │   │   └───Simple
│       │               │   │   ├───Probe
│       │               │   │   │   └───Perl
│       │               │   │   ├───Regexp
│       │               │   │   │   └───Common
│       │               │   │   ├───Tee
│       │               │   │   ├───Term
│       │               │   │   │   ├───ReadKey
│       │               │   │   │   └───ReadLine
│       │               │   │   ├───Test
│       │               │   │   │   ├───Pod
│       │               │   │   │   │   └───Coverage
│       │               │   │   │   └───Reporter
│       │               │   │   ├───URI
│       │               │   │   ├───version
│       │               │   │   │   └───vxs
│       │               │   │   ├───Win32API
│       │               │   │   │   └───File
│       │               │   │   ├───XML
│       │               │   │   │   ├───LibXML
│       │               │   │   │   │   └───Common
│       │               │   │   │   ├───NamespaceSupport
│       │               │   │   │   ├───Parser
│       │               │   │   │   │   └───Expat
│       │               │   │   │   └───SAX
│       │               │   │   └───YAML
│       │               │   ├───B
│       │               │   ├───Compress
│       │               │   │   └───Raw
│       │               │   ├───Digest
│       │               │   ├───HTML
│       │               │   ├───Math
│       │               │   │   └───BigInt
│       │               │   ├───Term
│       │               │   ├───version
│       │               │   ├───Win32API
│       │               │   │   └───File
│       │               │   └───XML
│       │               │       ├───LibXML
│       │               │       │   └───SAX
│       │               │       └───Parser
│       │               │           ├───Encodings
│       │               │           └───Style
│       │               ├───Net
│       │               │   └───HTTP
│       │               ├───PAR
│       │               ├───Pod
│       │               │   ├───Coverage
│       │               │   ├───Simple
│       │               │   └───Text
│       │               ├───Probe
│       │               ├───Regexp
│       │               │   └───Common
│       │               │       └───URI
│       │               ├───Term
│       │               │   └───ReadLine
│       │               ├───Test
│       │               │   ├───Pod
│       │               │   └───Reporter
│       │               │       ├───Date
│       │               │       ├───Mail
│       │               │       └───Time
│       │               ├───URI
│       │               │   ├───file
│       │               │   └───urn
│       │               ├───WWW
│       │               │   └───RobotRules
│       │               ├───XML
│       │               │   └───SAX
│       │               │       └───PurePerl
│       │               │           └───Reader
│       │               └───YAML
│       │                   ├───Dumper
│       │                   └───Loader
│       ├───postinstall
│       ├───sbin
│       │   └───awk
│       ├───share
│       │   ├───aclocal
│       │   ├───autogen
│       │   ├───awk
│       │   ├───bison
│       │   │   ├───m4sugar
│       │   │   └───xslt
│       │   ├───cvs
│       │   │   └───contrib
│       │   ├───doc
│       │   │   └───MSYS
│       │   ├───guile
│       │   │   └───1.8
│       │   │       ├───ice-9
│       │   │       │   ├───debugger
│       │   │       │   └───debugging
│       │   │       ├───lang
│       │   │       │   └───elisp
│       │   │       │       ├───internals
│       │   │       │       └───primitives
│       │   │       ├───oop
│       │   │       │   └───goops
│       │   │       ├───scripts
│       │   │       └───srfi
│       │   ├───locale
│       │   │   ├───da
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───de
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───eo
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───es
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───fr
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───hu
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───ja
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───nb
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───nl
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───pl
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───pt_BR
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───ru
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───sr
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───sv
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───uk
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───vi
│       │   │   │   └───LC_MESSAGES
│       │   │   ├───zh_CN
│       │   │   │   └───LC_MESSAGES
│       │   │   └───zh_TW
│       │   │       └───LC_MESSAGES
│       │   ├───misc
│       │   ├───texinfo
│       │   └───vim
│       │       └───vim73
│       │           ├───autoload
│       │           │   └───xml
│       │           ├───colors
│       │           ├───compiler
│       │           ├───ftplugin
│       │           ├───indent
│       │           ├───macros
│       │           │   ├───hanoi
│       │           │   ├───life
│       │           │   ├───maze
│       │           │   └───urm
│       │           ├───plugin
│       │           ├───print
│       │           ├───spell
│       │           ├───syntax
│       │           ├───tools
│       │           └───tutor
│       └───var
│           ├───empty
│           ├───run
│           └───ssl
│               ├───certs
│               │   ├───demo
│               │   └───expired
│               ├───misc
│               ├───private
│               └───rootcerts
├───share
│   ├───aclocal
│   ├───aclocal-1.10
│   ├───aclocal-1.11
│   ├───aclocal-1.4
│   ├───aclocal-1.5
│   ├───aclocal-1.6
│   ├───aclocal-1.7
│   ├───aclocal-1.8
│   ├───aclocal-1.9
│   ├───autoconf
│   │   ├───autoconf
│   │   ├───Autom4te
│   │   ├───autoscan
│   │   ├───autotest
│   │   └───m4sugar
│   ├───automake-1.10
│   │   ├───am
│   │   └───Automake
│   ├───automake-1.11
│   │   ├───am
│   │   └───Automake
│   ├───automake-1.4
│   ├───automake-1.5
│   │   ├───am
│   │   └───Automake
│   ├───automake-1.6
│   │   ├───am
│   │   └───Automake
│   ├───automake-1.7
│   │   ├───am
│   │   └───Automake
│   ├───automake-1.8
│   │   ├───am
│   │   └───Automake
│   ├───automake-1.9
│   │   ├───am
│   │   └───Automake
│   ├───autotools
│   ├───doc
│   │   ├───gcc
│   │   │   └───6.3.0
│   │   │       └───zlib
│   │   ├───MinGW
│   │   └───mingw-get
│   ├───gcc-6.3.0
│   │   └───python
│   │       └───libstdcxx
│   │           └───v6
│   ├───gdb
│   │   ├───python
│   │   │   └───gdb
│   │   │       ├───command
│   │   │       └───function
│   │   └───syscalls
│   ├───gettext
│   │   ├───intl
│   │   └───po
│   ├───libtool
│   │   ├───config
│   │   └───libltdl
│   │       ├───libltdl
│   │       └───loaders
│   └───locale
│       ├───be
│       │   └───LC_MESSAGES
│       ├───bg
│       │   └───LC_MESSAGES
│       ├───ca
│       │   └───LC_MESSAGES
│       ├───cs
│       │   └───LC_MESSAGES
│       ├───da
│       │   └───LC_MESSAGES
│       ├───de
│       │   └───LC_MESSAGES
│       ├───el
│       │   └───LC_MESSAGES
│       ├───en@boldquot
│       │   └───LC_MESSAGES
│       ├───en@quot
│       │   └───LC_MESSAGES
│       ├───eo
│       │   └───LC_MESSAGES
│       ├───es
│       │   └───LC_MESSAGES
│       ├───et
│       │   └───LC_MESSAGES
│       ├───eu
│       │   └───LC_MESSAGES
│       ├───fi
│       │   └───LC_MESSAGES
│       ├───fr
│       │   └───LC_MESSAGES
│       ├───ga
│       │   └───LC_MESSAGES
│       ├───gl
│       │   └───LC_MESSAGES
│       ├───hr
│       │   └───LC_MESSAGES
│       ├───id
│       │   └───LC_MESSAGES
│       ├───it
│       │   └───LC_MESSAGES
│       ├───ja
│       │   └───LC_MESSAGES
│       ├───ko
│       │   └───LC_MESSAGES
│       ├───nb
│       │   └───LC_MESSAGES
│       ├───nl
│       │   └───LC_MESSAGES
│       ├───nn
│       │   └───LC_MESSAGES
│       ├───pa
│       │   └───LC_MESSAGES
│       ├───pl
│       │   └───LC_MESSAGES
│       ├───pt
│       │   └───LC_MESSAGES
│       ├───pt_BR
│       │   └───LC_MESSAGES
│       ├───ro
│       │   └───LC_MESSAGES
│       ├───ru
│       │   └───LC_MESSAGES
│       ├───sk
│       │   └───LC_MESSAGES
│       ├───sl
│       │   └───LC_MESSAGES
│       ├───sr
│       │   └───LC_MESSAGES
│       ├───sv
│       │   └───LC_MESSAGES
│       ├───tr
│       │   └───LC_MESSAGES
│       ├───uk
│       │   └───LC_MESSAGES
│       ├───vi
│       │   └───LC_MESSAGES
│       ├───zh_CN
│       │   └───LC_MESSAGES
│       ├───zh_HK
│       │   └───LC_MESSAGES
│       └───zh_TW
│           └───LC_MESSAGES
└───var
    ├───cache
    │   └───mingw-get
    │       ├───data
    │       │   └───.in-transit
    │       └───packages
    │           └───.in-transit
    └───lib
        └───mingw-get
            └───data

I would appreciate that if you help me fix my problem. :-)

  • `g++ main.cpp -o main` You do not appear to link to sdl libraries so I would expect several linker errors. None of them have anything to do with the layout of your files or folder locations. – drescherjm May 10 '22 at 14:50
  • 1
    The linked thread should have all the information you need. Also [consider updating your compiler](https://stackoverflow.com/q/30069830/2752075). – HolyBlackCat May 10 '22 at 14:53
  • Thank you! Problem fixed! I think that I'm not so familiar with MinGW compiler... – Sodium Hypochlorite May 11 '22 at 00:02

0 Answers0