Несколько проблем Компиляция и запуск примера программы на C ++ в Windows - PullRequest
1 голос
/ 04 января 2012

Как видите, я очень новичок в этом сайте.Я искал, используя, чтобы найти проблемы, подобные моей, но безрезультатно.

Моя проблема в том, что я не могу скомпилировать программу на С ++ ( ссылка здесь Примечание: исходный код найден здесь ) и не нашли правильных способов исправить ошибки компилятора.

Я пробовал несколько способов компиляции:

1) Использование cygwin.

Я использовал make-файл, предоставленный для компиляции, и попытался запустить файл (у меня было много проблем с включением библиотек (GLEW, GLUT, GLM), но я исправил их после помещения библиотек в каталог cygwin.Затем он дал мне freeglut не удалось открыть ошибку дисплея, что я исправил при входе в xcygwin. Это дало мне последнюю ошибку при вызове отсутствующей версии GL. Люди на других сайтах говорили, что инициировали перенасыщение до glew, но я не мог найти гдеinit glew был запущен. Я не нашел никаких решений проблемы cygwin.

2) Использование компилятора g ++ через CMD.exe

Я читал, что вы можете скомпилировать C ++ черезкомандная подсказкат, поэтому я пытался это сделать.Я запустил команду g ++ glescraft.cpp noise.h noise.cpp textures.c -o glescraft, но также выдал ошибки о невозможности найти GLEW.Я исправил их еще раз, поместив библиотеки в правильное место.После того, как все проблемы с библиотекой были исправлены, она породила много проблем с несколькими объявлениями, а также с неопределенными ссылками на команды GL, GLEW и GLUT.Я могу опубликовать ошибки, если вы, ребята, нуждаетесь в них, кстати.Но я не верю, что в файлах есть ошибка программирования, поскольку программа, скомпилированная с использованием make на GNU / Linux, прекрасно работает, но я не смог протестировать из-за того, что у меня много проблем с драйверами nVIDIA (X не запускается и т. Д.так далее).Я попробовал компиляцию g ++ на gnu / linux, но с теми же множественными определениями и неопределенными ссылками.Я ничего не мог найти на них.

3) Code :: Blocks

То же самое произошло с использованием компилятора g ++, как я полагаю, code ::Blocks также использует компилятор mingw g ++.

Кстати, когда я сказал, что пробовал g ++ в командной строке, я также пробовал gcc, но также и те же ошибки.

Мой вопрос такой:Как я могу заставить эту программу компилироваться, и с небольшими зависимостями, насколько это возможно?

Можете ли вы, ребята, найти способ?Я в замешательстве, и не могу найти способ сделать это вообще, я пытался в течение недели или около того.

РЕДАКТИРОВАТЬ: Как отметил человек, вот ошибки:

Ошибки, отображаемые после использования компилятора g ++ в cmd, а также те же, что и в code :: blocks:

C:\prog\glescraft>g++ glescraft.cpp noise.h noise.cpp textures.c -o glescraft.ex
e
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x0): multiple d
efinition of `linearInterpolation(float, float, float)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x58): first
 defined here
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x11): multiple
definition of `biLinearInterpolation(float, float, float, float, float, float)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x69): first
 defined here
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x76): multiple
definition of `triLinearInterpolation(float, float, float, float, float, float,
float, float, float, float, float)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xce): first
 defined here
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x111): multiple
 definition of `noise2d(int, int, int)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x169): firs
t defined here
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x1e7): multiple
 definition of `noise3d(int, int, int, int)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x23f): firs
t defined here
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x2f4): multiple
 definition of `noise2d_gradient(float, float, int)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x34c): firs
t defined here
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x454): multiple
 definition of `noise3d_gradient(float, float, float, int)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x4ac): firs
t defined here
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x6e0): multiple
 definition of `noise2d_perlin(float, float, int, int, float)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x738): firs
t defined here
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x765): multiple
 definition of `noise2d_perlin_abs(float, float, int, int, float)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x7bd): firs
t defined here
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x7f6): multiple
 definition of `noise3d_perlin(float, float, float, int, int, float)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x84e): firs
t defined here
C:\Users\patrick\AppData\Local\Temp\ccCAHbwO.o:noise.cpp:(.text+0x885): multiple
 definition of `noise3d_perlin_abs(float, float, float, int, int, float)'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x8dd): firs
t defined here
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1c): undef
ined reference to `__glutInitWithExit'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x37): undef
ined reference to `__glutCreateWindowWithExit'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x52): undef
ined reference to `__glutCreateMenuWithExit'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xa9e): unde
fined reference to `_imp____glewIsShader'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xab9): unde
fined reference to `_imp____glewGetShaderiv'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xadc): unde
fined reference to `_imp____glewIsProgram'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xaf7): unde
fined reference to `_imp____glewGetProgramiv'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xb55): unde
fined reference to `_imp____glewIsShader'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xb70): unde
fined reference to `_imp____glewGetShaderInfoLog'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xb9a): unde
fined reference to `_imp____glewIsProgram'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xbb5): unde
fined reference to `_imp____glewGetProgramInfoLog'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xc51): unde
fined reference to `_imp____glewCreateShader'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xc66): unde
fined reference to `_imp____glewShaderSource'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xc9a): unde
fined reference to `_imp____glewCompileShader'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xcb3): unde
fined reference to `_imp____glewGetShaderiv'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xd05): unde
fined reference to `_imp____glewDeleteShader'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xe48): unde
fined reference to `glGetIntegerv@8'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xefc): unde
fined reference to `_imp____glewCreateProgram'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xf14): unde
fined reference to `_imp____glewAttachShader'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xf2f): unde
fined reference to `_imp____glewAttachShader'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xf4a): unde
fined reference to `_imp____glewLinkProgram'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xf5e): unde
fined reference to `_imp____glewGetProgramiv'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0xfc1): unde
fined reference to `_imp____glewGetAttribLocation'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1025): und
efined reference to `_imp____glewGetUniformLocation'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1082): und
efined reference to `_imp____glewActiveTexture'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x10ae): und
efined reference to `glGenTextures@8'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x10c6): und
efined reference to `glBindTexture@8'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1119): und
efined reference to `glTexImage2D@36'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1121): und
efined reference to `_imp____glewGenerateMipmap'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1211): und
efined reference to `_imp____glewGenBuffers'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1244): und
efined reference to `_imp____glewBindBuffer'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1260): und
efined reference to `_imp____glewBufferData'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x128d): und
efined reference to `_imp____glewGenBuffers'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x134e): und
efined reference to `glViewport@16'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x13a2): und
efined reference to `_imp____glewUseProgram'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x13b6): und
efined reference to `_imp____glewUniform1i'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x14f8): und
efined reference to `_imp____glewUniformMatrix4fv'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1552): und
efined reference to `glClearColor@16'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1561): und
efined reference to `glClear@4'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1580): und
efined reference to `glTexParameteri@12'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x159f): und
efined reference to `glTexParameteri@12'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x15ae): und
efined reference to `glEnable@4'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x15bd): und
efined reference to `glEnable@4'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x15d6): und
efined reference to `glPolygonOffset@8'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x15e5): und
efined reference to `glEnable@4'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x15ed): und
efined reference to `_imp____glewEnableVertexAttribArray'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1666): und
efined reference to `glReadPixels@28'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1e72): und
efined reference to `glDisable@4'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1e81): und
efined reference to `glDisable@4'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1e89): und
efined reference to `_imp____glewUniformMatrix4fv'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1ec0): und
efined reference to `_imp____glewBindBuffer'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1edc): und
efined reference to `_imp____glewBufferData'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1f09): und
efined reference to `_imp____glewVertexAttribPointer'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1f5c): und
efined reference to `glDrawArrays@12'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1f83): und
efined reference to `glDisable@4'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1fa7): und
efined reference to `_imp____glewUniformMatrix4fv'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1fde): und
efined reference to `_imp____glewBindBuffer'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x1ffa): und
efined reference to `_imp____glewBufferData'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x2027): und
efined reference to `_imp____glewVertexAttribPointer'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x207a): und
efined reference to `glDrawArrays@12'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x2082): und
efined reference to `glutSwapBuffers'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x22f4): und
efined reference to `glutGet'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x24d7): und
efined reference to `glutPostRedisplay'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x2643): und
efined reference to `glutWarpPointer'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x2825): und
efined reference to `_imp____glewDeleteProgram'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x2862): und
efined reference to `glutInitDisplayMode'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x2876): und
efined reference to `glutInitWindowSize'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x2887): und
efined reference to `_imp__glewInit'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x28a0): und
efined reference to `_imp__glewGetErrorString'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x28ce): und
efined reference to `_imp____GLEW_VERSION_2_0'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x296c): und
efined reference to `glutSetCursor'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x2980): und
efined reference to `glutWarpPointer'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x298c): und
efined reference to `glutDisplayFunc'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x2998): und
efined reference to `glutReshapeFunc'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x29a4): und
efined reference to `glutIdleFunc'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x29b0): und
efined reference to `glutSpecialFunc'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x29bc): und
efined reference to `glutSpecialUpFunc'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x29c8): und
efined reference to `glutIdleFunc'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x29d4): und
efined reference to `glutPassiveMotionFunc'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x29e0): und
efined reference to `glutMotionFunc'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x29ec): und
efined reference to `glutMouseFunc'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text+0x29f1): und
efined reference to `glutMainLoop'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text$_ZN5chunk6up
dateEv[chunk::update()]+0x237e): undefined reference to `_imp____glewGenBuffers'

C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text$_ZN5chunk6up
dateEv[chunk::update()]+0x23e9): undefined reference to `_imp____glewBindBuffer'

C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text$_ZN5chunk6up
dateEv[chunk::update()]+0x2409): undefined reference to `_imp____glewBufferData'

C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text$_ZN5chunk6re
nderEv[chunk::render()]+0x3f): undefined reference to `_imp____glewBindBuffer'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text$_ZN5chunk6re
nderEv[chunk::render()]+0x5f): undefined reference to `_imp____glewVertexAttribP
ointer'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text$_ZN5chunk6re
nderEv[chunk::render()]+0xb7): undefined reference to `glDrawArrays@12'
C:\Users\patrick\AppData\Local\Temp\ccL5KhgI.o:glescraft.cpp:(.text$_ZN10superch
unk6renderERKN3glm6detail7tmat4x4IfEE[superchunk::render(glm::detail::tmat4x4 const&)]+0x2c7): undefined reference to `_imp____glewUniformMatrix4fv'
collect2: ld returned 1 exit status

Извините за форматирование, я не могу получитькодовые теги, работающие на копирование-вставку.

1 Ответ

0 голосов
/ 04 января 2012

Некоторые из этих множественных ошибок определения связаны с тем, что файл glescraft.cpp включает в себя source файл noise.cpp и textures.c, и вы также пытаетесь скомпилировать его в командной строке. Либо измените источник, чтобы он включал правильные заголовочные файлы, либо скомпилируйте только glescraft.cpp.

Проблемы с неопределенными ссылками связаны с тем, что вы не связываетесь с библиотеками OpenGL. Добавьте как минимум «-lgl -lglut» в командную строку.

Вы также должны указать компилятору (фактически, компоновщику), где найти библиотеки. Это делается с помощью флага "-L".

Командная строка после моих предложений должна выглядеть примерно так:

g++ glescraft.cpp -o glescraft.exe -L<path to gl and glut libs> -lgl -lglut

Заменить "<path to gl and glut libs>" фактическим путем к библиотекам.

Кроме того, при компиляции заголовочные файлы (файлы, оканчивающиеся на «.h») никогда не должны компилироваться вами. Вместо этого они включаются компилятором с директивой #include "file".

Вы можете увидеть все флаги в руководстве GCC . Выберите версию, которую вы имеете (которую можно найти с помощью команды g++ --version.)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...