Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems building on Linux: undefined reference to max #43

Open
haasn opened this issue Oct 22, 2016 · 1 comment
Open

Problems building on Linux: undefined reference to max #43

haasn opened this issue Oct 22, 2016 · 1 comment

Comments

@haasn
Copy link

haasn commented Oct 22, 2016

I'm building as follows:

$ git clone https://github.com/James-Jones/HLSLCrossCompiler.git
$ cd HLSLCrossCompiler
$ mkdir build && cd build
$ cmake ../mk
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
SETTING Little endian
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nand/dev/HLSLCrossCompiler/build
$ make
...
[ 97%] Linking CXX executable /home/nand/dev/HLSLCrossCompiler/bin/HLSLcc
/home/nand/dev/HLSLCrossCompiler/lib/liblibHLSLcc.a(toGLSLInstruction.c.o): In function `AddComparision':
toGLSLInstruction.c:(.text+0x1819): undefined reference to `max'
/home/nand/dev/HLSLCrossCompiler/lib/liblibHLSLcc.a(toGLSLOperand.c.o): In function `TranslateVariableNameWithMask':
toGLSLOperand.c:(.text+0x1ec2): undefined reference to `max'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/HLSLcc.dir/build.make:174: /home/nand/dev/HLSLCrossCompiler/bin/HLSLcc] Error 1
make[1]: *** [CMakeFiles/Makefile2:142: CMakeFiles/HLSLcc.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[100%] Linking CXX executable /home/nand/dev/HLSLCrossCompiler/bin/HLSLcc-i386
/home/nand/dev/HLSLCrossCompiler/lib/liblibHLSLcc-i386.a(toGLSLInstruction.c.o): In function `AddComparision':
toGLSLInstruction.c:(.text+0x188b): undefined reference to `max'
/home/nand/dev/HLSLCrossCompiler/lib/liblibHLSLcc-i386.a(toGLSLOperand.c.o): In function `TranslateVariableNameWithMask':
toGLSLOperand.c:(.text+0x1f04): undefined reference to `max'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/HLSLcc-i386.dir/build.make:174: /home/nand/dev/HLSLCrossCompiler/bin/HLSLcc-i386] Error 1
make[1]: *** [CMakeFiles/Makefile2:179: CMakeFiles/HLSLcc-i386.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
@haasn
Copy link
Author

haasn commented Oct 22, 2016

Note that the following changes make it compile successfully

diff --git a/src/toGLSLInstruction.c b/src/toGLSLInstruction.c
index eee67af..1a9727c 100644
--- a/src/toGLSLInstruction.c
+++ b/src/toGLSLInstruction.c
@@ -10,6 +10,10 @@
 #define min(a,b)            (((a) < (b)) ? (a) : (b))
 #endif

+#ifndef max
+#define max(a,b)            (((a) > (b)) ? (a) : (b))
+#endif
+
 extern void AddIndentation(HLSLCrossCompilerContext* psContext);
 static int IsIntegerImmediateOpcode(OPCODE_TYPE eOpcode);

diff --git a/src/toGLSLOperand.c b/src/toGLSLOperand.c
index 0f00f2d..32397f6 100644
--- a/src/toGLSLOperand.c
+++ b/src/toGLSLOperand.c
@@ -12,6 +12,10 @@
 #define isinf(x) (!_finite(x))
 #endif

+#ifndef max
+#define max(a,b)   (((a) > (b)) ? (a) : (b))
+#endif
+
 #define fpcheck(x) (isnan(x) || isinf(x))

 extern void AddIndentation(HLSLCrossCompilerContext* psContext);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant